Best Python code snippet using elementium_python
view_validation.py
Source:view_validation.py  
...49    return True50@validate('form')51def valid_page_in_book(arch):52    """A `page` node must be below a `notebook` node."""53    return not arch.xpath('//page[not(ancestor::notebook)]')54@validate('graph')55def valid_field_in_graph(arch):56    """ Children of ``graph`` can only be ``field`` """57    return all(58        child.tag == 'field'59        for child in arch.xpath('/graph/*')60    )61@validate('tree')62def valid_field_in_tree(arch):63    """ Children of ``tree`` view must be ``field`` or ``button`` or ``control``."""64    return all(65        child.tag in ('field', 'button', 'control')66        for child in arch.xpath('/tree/*')67    )68@validate('form', 'graph', 'tree')69def valid_att_in_field(arch):70    """ ``field`` nodes must all have a ``@name`` """71    return not arch.xpath('//field[not(@name)]')72@validate('form')73def valid_att_in_label(arch):74    """ ``label`` nodes must have a ``@for`` """75    return not arch.xpath('//label[not(@for) and not(descendant::input)]')76@validate('form')77def valid_att_in_form(arch):78    return True79@validate('form')80def valid_type_in_colspan(arch):81    """A `colspan` attribute must be an `integer` type."""82    return all(83        attrib.isdigit()84        for attrib in arch.xpath('//@colspan')85    )86@validate('form')87def valid_type_in_col(arch):88    """A `col` attribute must be an `integer` type."""89    return all(90        attrib.isdigit()91        for attrib in arch.xpath('//@col')92    )93@validate('calendar', 'diagram', 'form', 'graph', 'kanban', 'pivot', 'search', 'tree')94def valid_alternative_image_text(arch):95    """An `img` tag must have an alt value."""96    if arch.xpath('//img[not(@alt or @t-att-alt or @t-attf-alt)]'):97        return "Warning"98    return True99@validate('calendar', 'diagram', 'form', 'graph', 'kanban', 'pivot', 'search', 'tree')100def valid_alternative_icon_text(arch):101    """An icon with fa- class or in a button must have aria-label in its tag, parents, descendants or have text."""102    valid_aria_attrs = {103        'aria-label', 'aria-labelledby', 't-att-aria-label', 't-attf-aria-label',104        't-att-aria-labelledby', 't-attf-aria-labelledby'}105    valid_t_attrs = {'t-value', 't-raw', 't-field', 't-esc'}106    valid_attrs = valid_aria_attrs | valid_t_attrs107    valid_aria_attrs_xpath = ' or '.join('@' + attr for attr in valid_aria_attrs)108    valid_attrs_xpath = ' or '.join('@' + attr for attr in valid_attrs)109    # Select elements with class begining by 'fa-'110    xpath = '(//*[contains(concat(" ", @class), " fa-")'111    xpath += ' or contains(concat(" ", @t-att-class), " fa-")'112    xpath += ' or contains(concat(" ", @t-attf-class), " fa-")]'113    xpath += ' | //button[@icon])'114    # Elements with accessibility or string attrs are good115    xpath += '[not(' + valid_attrs_xpath + ')]'116    # And we ignore all elements with describing in children117    xpath += '[not(//*[' + valid_attrs_xpath + '])]'118    # Aria label can be on ancestors119    xpath += '[not(ancestor[' + valid_aria_attrs_xpath + '])]'120    # Labels provide text by definition121    xpath += '[not(descendant-or-self::label)]'122    # Buttons can have a string attribute123    xpath += '[not(descendant-or-self::button[@string])]'124    # Fields have labels125    xpath += '[not(descendant-or-self::field)]'126    # And finally, if there is some text, it's good too127    xpath += '[not(descendant-or-self::*[text()])]'128    # Following or preceding text129    xpath += '[not(preceding-sibling::text()[normalize-space()])]'130    xpath += '[not(following-sibling::text()[normalize-space()])]'131    # Following or preceding text in span132    xpath += '[not(preceding-sibling::span[text()])]'133    xpath += '[not(following-sibling::span[text()])]'134    if arch.xpath(xpath):135        return "Warning"136    return True137@validate('calendar', 'diagram', 'form', 'graph', 'kanban', 'pivot', 'search', 'tree')138def valid_title_icon(arch):139    """An icon with fa- class or in a button must have title in its tag, parents, descendants or have text."""140    valid_title_attrs = {'title', 't-att-title', 't-attf-title'}141    valid_t_attrs = {'t-value', 't-raw', 't-field', 't-esc'}142    valid_attrs = valid_title_attrs | valid_t_attrs143    valid_title_attrs_xpath = ' or '.join('@' + attr for attr in valid_title_attrs)144    valid_attrs_xpath = ' or '.join('@' + attr for attr in valid_attrs)145    # Select elements with class begining by 'fa-'146    xpath = '(//*[contains(concat(" ", @class), " fa-")'147    xpath += ' or contains(concat(" ", @t-att-class), " fa-")'148    xpath += ' or contains(concat(" ", @t-attf-class), " fa-")]'149    xpath += ' | //button[@icon])'150    # Elements with accessibility or string attrs are good151    xpath += '[not(' + valid_attrs_xpath + ')]'152    # And we ignore all elements with describing in children153    xpath += '[not(//*[' + valid_attrs_xpath + '])]'154    # Aria label can be on ancestors155    xpath += '[not(ancestor[' + valid_title_attrs_xpath + '])]'156    # Labels provide text by definition157    xpath += '[not(descendant-or-self::label)]'158    # Buttons can have a string attribute159    xpath += '[not(descendant-or-self::button[@string])]'160    # Fields have labels161    xpath += '[not(descendant-or-self::field)]'162    # And finally, if there is some text, it's good too163    xpath += '[not(descendant-or-self::*[text()])]'164    # Following or preceding text165    xpath += '[not(preceding-sibling::text()[normalize-space()])]'166    xpath += '[not(following-sibling::text()[normalize-space()])]'167    # Following or preceding text in span168    xpath += '[not(preceding-sibling::span[text()])]'169    xpath += '[not(following-sibling::span[text()])]'170    if arch.xpath(xpath):171        return "Warning"172    return True173@validate('calendar', 'diagram', 'form', 'graph', 'kanban', 'pivot', 'search', 'tree')174def valid_simili_button(arch):175    """A simili button must be tagged with "role='button'"."""176    # Select elements with class 'btn'177    xpath = '//a[contains(concat(" ", @class), " btn")'178    xpath += ' or contains(concat(" ", @t-att-class), " btn")'179    xpath += ' or contains(concat(" ", @t-attf-class), " btn")]'180    xpath += '[not(@role="button")]'181    if arch.xpath(xpath):182        return "Warning"183    return True184@validate('calendar', 'diagram', 'form', 'graph', 'kanban', 'pivot', 'search', 'tree')185def valid_simili_dropdown(arch):186    """A simili dropdown must be tagged with "role='menu'"."""187    xpath = '//*[contains(concat(" ", @class, " "), " dropdown-menu ")'188    xpath += ' or contains(concat(" ", @t-att-class, " "), " dropdown-menu ")'189    xpath += ' or contains(concat(" ", @t-attf-class, " "), " dropdown-menu ")]'190    xpath += '[not(@role="menu")]'191    if arch.xpath(xpath):192        return "Warning"193    return True194@validate('calendar', 'diagram', 'form', 'graph', 'kanban', 'pivot', 'search', 'tree')195def valid_simili_progressbar(arch):196    """A simili progressbar must be tagged with "role='progressbar'" and have197    aria-valuenow, aria-valuemin and aria-valuemax attributes."""198    # Select elements with class 'btn'199    xpath = '//*[contains(concat(" ", @class, " "), " o_progressbar ")'200    xpath += ' or contains(concat(" ", @t-att-class, " "), " o_progressbar ")'201    xpath += ' or contains(concat(" ", @t-attf-class, " "), " o_progressbar ")]'202    xpath += '[not(self::progress)]'203    xpath += '[not(@role="progressbar")]'204    xpath += '[not(@aria-valuenow or @t-att-aria-valuenow or @t-attf-aria-valuenow)]'205    xpath += '[not(@aria-valuemin or @t-att-aria-valuemin or @t-attf-aria-valuemin)]'206    xpath += '[not(@aria-valuemax or @t-att-aria-valuemax or @t-attf-aria-valuemax)]'207    if arch.xpath(xpath):208        return "Warning"209    return True210@validate('calendar', 'diagram', 'form', 'graph', 'kanban', 'pivot', 'search', 'tree')211def valid_dialog(arch):212    """A dialog must use role="dialog" and its header, body and footer contents must use <header/>, <main/> and <footer/>."""213    # Select elements with class 'btn'214    xpath = '//*[contains(concat(" ", @class, " "), " modal ")'215    xpath += ' or contains(concat(" ", @t-att-class, " "), " modal ")'216    xpath += ' or contains(concat(" ", @t-attf-class, " "), " modal ")]'217    xpath += '[not(@role="dialog")]'218    if arch.xpath(xpath):219        return "Warning"220    xpath = '//*[contains(concat(" ", @class, " "), " modal-header ")'221    xpath += ' or contains(concat(" ", @t-att-class, " "), " modal-header ")'222    xpath += ' or contains(concat(" ", @t-attf-class, " "), " modal-header ")]'223    xpath += '[not(self::header)]'224    if arch.xpath(xpath):225        return "Warning"226    xpath = '//*[contains(concat(" ", @class, " "), " modal-body ")'227    xpath += ' or contains(concat(" ", @t-att-class, " "), " modal-body ")'228    xpath += ' or contains(concat(" ", @t-attf-class, " "), " modal-body ")]'229    xpath += '[not(self::main)]'230    if arch.xpath(xpath):231        return "Warning"232    xpath = '//*[contains(concat(" ", @class, " "), " modal-footer ")'233    xpath += ' or contains(concat(" ", @t-att-class, " "), " modal-footer ")'234    xpath += ' or contains(concat(" ", @t-attf-class, " "), " modal-footer ")]'235    xpath += '[not(self::footer)]'236    if arch.xpath(xpath):237        return "Warning"238    return True239@validate('calendar', 'diagram', 'form', 'graph', 'kanban', 'pivot', 'search', 'tree')240def valid_simili_tabpanel(arch):241    """A tab panel with tab-pane class must have role="tabpanel"."""242    # Select elements with class 'btn'243    xpath = '//*[contains(concat(" ", @class, " "), " tab-pane ")'244    xpath += ' or contains(concat(" ", @t-att-class, " "), " tab-pane ")'245    xpath += ' or contains(concat(" ", @t-attf-class, " "), " tab-pane ")]'246    xpath += '[not(@role="tabpanel")]'247    if arch.xpath(xpath):248        return "Warning"249    return True250@validate('calendar', 'diagram', 'form', 'graph', 'kanban', 'pivot', 'search', 'tree')251def valid_simili_tab(arch):252    """A tab link must have role="tab", a link to an id (without #) by aria-controls."""253    # Select elements with class 'btn'254    xpath = '//*[@data-toggle="tab"]'255    xpath += '[not(@role="tab")'256    xpath += 'or not(@aria-controls or @t-att-aria-controls or @t-attf-aria-controls)'257    xpath += 'or contains(@aria-controls, "#") or contains(@t-att-aria-controls, "#")]'258    if arch.xpath(xpath):259        return "Warning"260    return True261@validate('calendar', 'diagram', 'form', 'graph', 'kanban', 'pivot', 'search', 'tree')262def valid_simili_tablist(arch):263    """A tab list with class nav-tabs must have role="tablist"."""264    # Select elements with class 'btn'265    xpath = '//*[contains(concat(" ", @class, " "), " nav-tabs ")'266    xpath += ' or contains(concat(" ", @t-att-class, " "), " nav-tabs ")'267    xpath += ' or contains(concat(" ", @t-attf-class, " "), " nav-tabs ")]'268    xpath += '[not(@role="tablist")]'269    if arch.xpath(xpath):270        return "Warning"271    return True272@validate('calendar', 'diagram', 'form', 'graph', 'kanban', 'pivot', 'search', 'tree')273def valid_focusable_button(arch):274    """A simili button must be with a `button`, an `input` (with type `button`, `submit` or `reset`) or a `a` tag."""275    xpath = '//*[contains(concat(" ", @class), " btn")'276    xpath += ' or contains(concat(" ", @t-att-class), " btn")'277    xpath += ' or contains(concat(" ", @t-attf-class), " btn")]'278    xpath += '[not(self::a)]'279    xpath += '[not(self::button)]'280    xpath += '[not(self::select)]'281    xpath += '[not(self::input[@type="button"])]'282    xpath += '[not(self::input[@type="submit"])]'283    xpath += '[not(self::input[@type="reset"])]'284    xpath += '[not(contains(@class, "btn-group"))]'285    xpath += '[not(contains(@t-att-class, "btn-group"))]'286    xpath += '[not(contains(@t-attf-class, "btn-group"))]'287    xpath += '[not(contains(@class, "btn-toolbar"))]'288    xpath += '[not(contains(@t-att-class, "btn-toolbar"))]'289    xpath += '[not(contains(@t-attf-class, "btn-toolbar"))]'290    xpath += '[not(contains(@class, "btn-ship"))]'291    xpath += '[not(contains(@t-att-class, "btn-ship"))]'292    xpath += '[not(contains(@t-attf-class, "btn-ship"))]'293    if arch.xpath(xpath):294        return "Warning"295    return True296@validate('calendar', 'diagram', 'form', 'graph', 'kanban', 'pivot', 'search', 'tree')297def valid_prohibited_none_role(arch):298    """A role can't be `none` or `presentation`. All your elements must be accessible with screen readers, describe it."""299    xpath = '//*[@role="none" or @role="presentation"]'300    if arch.xpath(xpath):301        return "Warning"302    return True303@validate('calendar', 'diagram', 'form', 'graph', 'kanban', 'pivot', 'search', 'tree')304def valid_alerts(arch):305    """An alert (class alert-*) must have an alert, alertdialog or status role. Please use alert and alertdialog only for what expects to stop any activity to be read immediatly."""306    xpath = '//*[contains(concat(" ", @class), " alert-")'307    xpath += ' or contains(concat(" ", @t-att-class), " alert-")'308    xpath += ' or contains(concat(" ", @t-attf-class), " alert-")]'309    xpath += '[not(contains(@class, "alert-link") or contains(@t-att-class, "alert-link")'310    xpath += ' or contains(@t-attf-class, "alert-link"))]'311    xpath += '[not(@role="alert")]'312    xpath += '[not(@role="alertdialog")]'313    xpath += '[not(@role="status")]'314    if arch.xpath(xpath):315        return "Warning"...w3c_xml.js
Source:w3c_xml.js  
1/*2 * Copyright 2008 Google Inc.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 *     http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16/**17 * @fileoverview Definitions for W3C's XML related specifications.18 *  This file depends on w3c_dom2.js.19 *  The whole file has been fully type annotated.20 *21 *  Provides the XML standards from W3C.22 *   Includes:23 *    XPath          - Fully type annotated24 *    XMLHttpRequest - Fully type annotated25 *26 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html27 * @see http://www.w3.org/TR/XMLHttpRequest/28 * @see http://www.w3.org/TR/XMLHttpRequest2/29 *30 * @externs31 */32/**33 * @constructor34 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathException35 */36function XPathException() {}37/**38 * @type {number}39 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#INVALID_EXPRESSION_ERR40 */41XPathException.INVALID_EXPRESSION_ERR = 52;42/**43 * @type {number}44 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#TYPE_ERR45 */46XPathException.TYPE_ERR = 52;47/**48 * @type {number}49 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#50 */51XPathException.prototype.code;52/**53 * @constructor54 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathEvaluator55 */56function XPathEvaluator() {}57/**58 * @param {string} expr59 * @param {?XPathNSResolver=} opt_resolver60 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathEvaluator-createExpression61 * @throws XPathException62 * @throws DOMException63 */64XPathEvaluator.prototype.createExpression = function(expr, opt_resolver) {};65/**66 * @param {Node} nodeResolver67 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathEvaluator-createNSResolver68 */69XPathEvaluator.prototype.createNSResolver = function(nodeResolver) {};70/**71 * @param {string} expr72 * @param {Node} contextNode73 * @param {?XPathNSResolver=} opt_resolver74 * @param {?number=} opt_type75 * @param {*=} opt_result76 * @return {XPathResult}77 * @throws XPathException78 * @throws DOMException79 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathEvaluator-evaluate80 */81XPathEvaluator.prototype.evaluate = function(expr, contextNode, opt_resolver,82    opt_type, opt_result) {};83/**84 * @constructor85 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathExpression86 */87function XPathExpression() {}88/**89 * @param {Node} contextNode90 * @param {number=} opt_type91 * @param {*=} opt_result92 * @return {*}93 * @throws XPathException94 * @throws DOMException95 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathExpression-evaluate96 */97XPathExpression.prototype.evaluate = function(contextNode, opt_type,98    opt_result) {};99/**100 * @constructor101 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathNSResolver102 */103function XPathNSResolver() {}104/**105 * @param {string} prefix106 * @return {?string}107 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathNSResolver-lookupNamespaceURI108 */109XPathNSResolver.prototype.lookupNamespaceURI = function(prefix) {};110/**111 * From http://www.w3.org/TR/xpath112 *113 * XPath is a language for addressing parts of an XML document, designed to be114 * used by both XSLT and XPointer.115 *116 * @noalias117 * @constructor118 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathResult119 */120function XPathResult() {}121/**122 * @type {boolean} {@see XPathException.TYPE_ERR}123 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathResult-booleanValue124 */125XPathResult.prototype.booleanValue;126/**127 * @type {boolean} {@see XPathException.TYPE_ERR}128 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathResult-invalid-iterator-state129 */130XPathResult.prototype.invalidInteratorState;131/**132 * @type {number}133 * @throws XPathException {@see XPathException.TYPE_ERR}134 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathResult-numberValue135 */136XPathResult.prototype.numberValue;137/**138 * @type {number}139 * @throws XPathException {@see XPathException.TYPE_ERR}140 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathResult-resultType141 */142XPathResult.prototype.resultType;143/**144 * @type {Node}145 * @throws XPathException {@see XPathException.TYPE_ERR}146 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathResult-singleNodeValue147 */148XPathResult.prototype.singleNodeValue;149/**150 * @type {number}151 * @throws XPathException {@see XPathException.TYPE_ERR}152 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathResult-snapshot-length153 */154XPathResult.prototype.snapshotLength;155/**156 * @type {string}157 * @throws XPathException {@see XPathException.TYPE_ERR}158 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathResult-stringValue159 */160XPathResult.prototype.stringValue;161/**162 * @return {Node}163 * @throws XPathException {@see XPathException.TYPE_ERR}164 * @throws DOMException {@see DOMException.INVALID_STATE_ERR}165 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathResult-iterateNext166 */167XPathResult.prototype.iterateNext = function() {};168/**169 * @param {number} index170 * @return {Node}171 * @throws XPathException172 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathResult-snapshotItem173 */174XPathResult.prototype.snapshotItem = function(index) {};175/**176 * @type {number}177 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathResult-ANY-TYPE178 */179XPathResult.ANY_TYPE = 0;180/**181 * @type {number}182 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathResult-NUMBER-TYPE183 */184XPathResult.NUMBER_TYPE = 1;185/**186 * @type {number}187 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathResult-STRING-TYPE188 */189XPathResult.STRING_TYPE = 2;190/**191 * @type {number}192 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathResult-BOOLEAN-TYPE193 */194XPathResult.BOOLEAN_TYPE = 3;195/**196 * @type {number}197 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathResult-UNORDERED-NODE-ITERATOR-TYPE198 */199XPathResult.UNORDERED_NODE_ITERATOR_TYPE = 4;200/**201 * @type {number}202 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathResult-ORDERED-NODE-ITERATOR-TYPE203 */204XPathResult.ORDERED_NODE_ITERATOR_TYPE = 5;205/**206 * @type {number}207 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathResult-UNORDERED-NODE-SNAPSHOT-TYPE208 */209XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE = 6;210/**211 * @type {number}212 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathResult-ORDERED-NODE-SNAPSHOT-TYPE213 */214XPathResult.ORDERED_NODE_SNAPSHOT_TYPE = 7;215/**216 * @type {number}217 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathResult-ANY-UNORDERED-NODE-TYPE218 */219XPathResult.ANY_UNORDERED_NODE_TYPE = 8;220/**221 * @type {number}222 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathResult-FIRST-ORDERED-NODE-TYPE223 */224XPathResult.FIRST_ORDERED_NODE_TYPE = 9;225/**226 * @constructor227 * @extends {Node}228 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathNamespace229 */230function XPathNamespace() {}231/**232 * @type {Element}233 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPathNamespace-ownerElement234 */235XPathNamespace.prototype.ownerElement;236/**237 * @type {number}238 * @see http://www.w3.org/TR/DOM-Level-3-XPath/xpath.html#XPATH_NAMESPACE_NODE239 */240XPathNamespace.XPATH_NAMESPACE_NODE = 13;241/**242 * From http://www.w3.org/TR/XMLHttpRequest/243 *244 * (Draft)245 *246 * The XMLHttpRequest Object specification defines an API that provides247 * scripted client functionality for transferring data between a client and a248 * server.249 *250 * @constructor251 * @see http://www.w3.org/TR/XMLHttpRequest/#xmlhttprequest-object252 */253function XMLHttpRequest() {}254/**255 * @param {string} method256 * @param {string} url257 * @param {?boolean=} opt_async258 * @param {?string=} opt_user259 * @param {?string=} opt_password260 * @return {undefined}261 * @see http://www.w3.org/TR/XMLHttpRequest/#open262 */263XMLHttpRequest.prototype.open = function(method, url, opt_async, opt_user,264    opt_password) {};265/**266 * @param {string} header267 * @param {string} value268 * @return {undefined}269 * @see http://www.w3.org/TR/XMLHttpRequest/#setrequestheader270 */271XMLHttpRequest.prototype.setRequestHeader = function(header, value) {};272/**273 * @param {ArrayBuffer|Blob|Document|FormData|string=} opt_data274 * @return {undefined}275 * @see http://www.w3.org/TR/XMLHttpRequest/#send276 * @see http://dev.w3.org/2006/webapi/XMLHttpRequest-2/#the-send-method277 */278XMLHttpRequest.prototype.send = function(opt_data) {};279/**280 * @return {undefined}281 * @see http://www.w3.org/TR/XMLHttpRequest/#abort282 */283XMLHttpRequest.prototype.abort = function() {};284/**285 * @return {string}286 * @see http://www.w3.org/TR/XMLHttpRequest/#getallresponseheaders287 */288XMLHttpRequest.prototype.getAllResponseHeaders = function() {};289/**290 * @param {string} header291 * @return {string}292 * @see http://www.w3.org/TR/XMLHttpRequest/#getresponseheader293 */294XMLHttpRequest.prototype.getResponseHeader = function(header) {};295/**296 * @type {string}297 * @see http://www.w3.org/TR/XMLHttpRequest/#responsetext298 */299XMLHttpRequest.prototype.responseText;300/**301 * @type {Document}302 * @see http://www.w3.org/TR/XMLHttpRequest/#responsexml303 */304XMLHttpRequest.prototype.responseXML;305/**306 * @type {number}307 * @see http://www.w3.org/TR/XMLHttpRequest/#readystate308 */309XMLHttpRequest.prototype.readyState;310/**311 * @type {number}312 * @see http://www.w3.org/TR/XMLHttpRequest/#status313 */314XMLHttpRequest.prototype.status;315/**316 * @type {string}317 * @see http://www.w3.org/TR/XMLHttpRequest/#statustext318 */319XMLHttpRequest.prototype.statusText;320/**321 * @type {Function}322 * @see http://www.w3.org/TR/XMLHttpRequest/#onreadystatechange323 */324XMLHttpRequest.prototype.onreadystatechange;325/**326 * The FormData object represents an ordered collection of entries. Each entry327 * has a name and value.328 *329 * @constructor330 * @see http://www.w3.org/TR/XMLHttpRequest2/#the-formdata-interface331 */332function FormData() {}333/**334 * @param {string} name335 * @param {Blob|string} value336 */...fireemblem.py
Source:fireemblem.py  
...21            "Recommended IVs": self.recommended_IV(response),22            "Stats": self.five_star_hero_stats(response)23        }24    def fullname(self, response):25        return response.selector.xpath('//h1[@class="page-title"]/span/span/text()').get()26    def tier(self, response):27        path = response.selector.xpath("//div[@class='hero-rating']/a/img/@src").get()28        return path.split("/")[-1][0]29    def movement(self, response):30        return response.selector.xpath('//div[@id="hero-atts"]/div[1]/div/h2/a/div/span/text()').get()31    def weapon(self, response):32        return response.selector.xpath('//div[@id="hero-atts"]/div[2]/div/h2/a/div/span/text()').get()33    34    def BST(self, response):35        return response.selector.xpath('//div[@id="max-stats"]/span[2]/text()').get()36    def recommended_build(self, response):37        # Only returns optimal builds chosen by Gamepress38        skillset = []39        for table in response.selector.xpath('(//div[@class="optimal-build"])'):40            skillset.append({41                "Weapon": table.xpath('.//following-sibling::table/tbody/tr[1]/td[1]/a/text()').get(),42                "Assist": table.xpath('.//following-sibling::table/tbody/tr[2]/td[1]/a/text()').get(),43                "Special": table.xpath('.//following-sibling::table/tbody/tr[3]/td[1]/a/text()').get(),44                "A Skill": table.xpath('.//following-sibling::table/tbody/tr[1]/td[2]/a/text()').get(),45                "B Skill": table.xpath('.//following-sibling::table/tbody/tr[2]/td[2]/a/text()').get(),46                "C Skill": table.xpath('.//following-sibling::table/tbody/tr[3]/td[2]/a/text()').get(),47                "S Skill": table.xpath('.//following-sibling::table/tbody/tr[4]/td/a/text()').get(),48                "SP": table.xpath('.//following-sibling::table/tbody/tr[4]/td/text()').get()49            })50        return skillset51    def recommended_IV(self, response):52        # Returns the ratings worst, average, or best for each stat53        IVs = []54        for iv in response.selector.xpath('//table[@id="iv-set-table"]/tbody/tr[2]'):55            IVs.append({56                "HP": iv.xpath('.//td[1]/div/div/h2/a/div/span/text()').get(),57                "ATK": iv.xpath('.//td[2]/div/div/h2/a/div/span/text()').get(),58                "SPD": iv.xpath('.//td[3]/div/div/h2/a/div/span/text()').get(),59                "DEF": iv.xpath('.//td[4]/div/div/h2/a/div/span/text()').get(),60                "RES": iv.xpath('.//td[5]/div/div/h2/a/div/span/text()').get()61            })62        return IVs63    64    def five_star_hero_stats(self,response):65        stats = []66        for stat in response.selector.xpath('//div[@id="stats-iv"]'):67            stats.append({68                # Lv1 Stats69                "1": {70                    "No Weapon": {71                        # Format is [Low, Medium, High]. If only Medium exists (i.e. Alfonse), then null is returned for Low and High.72                        "HP": [stat.xpath('.//table[1]/tbody/tr[2]/td[1]/span[1]/text()').get(), stat.xpath('.//table[1]/tbody/tr[3]/td[1]/span[1]/text()').get(), stat.xpath('.//table[1]/tbody/tr[4]/td[1]/span[1]/text()').get()],73                        "ATK": [stat.xpath('.//table[1]/tbody/tr[2]/td[2]/span[1]/text()').get(), stat.xpath('.//table[1]/tbody/tr[3]/td[2]/span[1]/text()').get(), stat.xpath('.//table[1]/tbody/tr[4]/td[2]/span[1]/text()').get()],74                        "SPD": [stat.xpath('.//table[1]/tbody/tr[2]/td[3]/span[1]/text()').get(), stat.xpath('.//table[1]/tbody/tr[3]/td[3]/span[1]/text()').get(), stat.xpath('.//table[1]/tbody/tr[4]/td[3]/span[1]/text()').get()],75                        "DEF": [stat.xpath('.//table[1]/tbody/tr[2]/td[4]/span[1]/text()').get(), stat.xpath('.//table[1]/tbody/tr[3]/td[4]/span[1]/text()').get(), stat.xpath('.//table[1]/tbody/tr[4]/td[4]/span[1]/text()').get()],76                        "RES": [stat.xpath('.//table[1]/tbody/tr[2]/td[5]/span[1]/text()').get(), stat.xpath('.//table[1]/tbody/tr[3]/td[5]/span[1]/text()').get(), stat.xpath('.//table[1]/tbody/tr[4]/td[5]/span[1]/text()').get()]77                    },78                    "Weapon" : {79                        "HP": [stat.xpath('.//table[1]/tbody/tr[2]/td[1]/span[2]/text()').get(), stat.xpath('.//table[1]/tbody/tr[3]/td[1]/span[2]/text()').get(), stat.xpath('.//table[1]/tbody/tr[4]/td[1]/span[2]/text()').get()],80                        "ATK": [stat.xpath('.//table[1]/tbody/tr[2]/td[2]/span[2]/text()').get(), stat.xpath('.//table[1]/tbody/tr[3]/td[2]/span[2]/text()').get(), stat.xpath('.//table[1]/tbody/tr[4]/td[2]/span[2]/text()').get()],81                        "SPD": [stat.xpath('.//table[1]/tbody/tr[2]/td[3]/span[2]/text()').get(), stat.xpath('.//table[1]/tbody/tr[3]/td[3]/span[2]/text()').get(), stat.xpath('.//table[1]/tbody/tr[4]/td[3]/span[2]/text()').get()],82                        "DEF": [stat.xpath('.//table[1]/tbody/tr[2]/td[4]/span[2]/text()').get(), stat.xpath('.//table[1]/tbody/tr[3]/td[4]/span[2]/text()').get(), stat.xpath('.//table[1]/tbody/tr[4]/td[4]/span[2]/text()').get()],83                        "RES": [stat.xpath('.//table[1]/tbody/tr[2]/td[5]/span[2]/text()').get(), stat.xpath('.//table[1]/tbody/tr[3]/td[5]/span[2]/text()').get(), stat.xpath('.//table[1]/tbody/tr[4]/td[5]/span[2]/text()').get()]84                    }85                },86                # Lv40 Stats87                "40": {88                    "No Weapon": {89                        "HP": [stat.xpath('.//table[contains(@id, "max")]/tbody/tr[2]/td[1]/span[1]/text()').get(), stat.xpath('.//table[contains(@id, "max")]/tbody/tr[3]/td[1]/span[1]/text()').get(), stat.xpath('.//table[contains(@id, "max")]/tbody/tr[4]/td[1]/span[1]/text()').get()],90                        "ATK": [stat.xpath('.//table[contains(@id, "max")]/tbody/tr[2]/td[2]/span[1]/text()').get(), stat.xpath('.//table[contains(@id, "max")]/tbody/tr[3]/td[2]/span[1]/text()').get(), stat.xpath('.//table[contains(@id, "max")]/tbody/tr[4]/td[2]/span[1]/text()').get()],91                        "SPD": [stat.xpath('.//table[contains(@id, "max")]/tbody/tr[2]/td[3]/span[1]/text()').get(), stat.xpath('.//table[contains(@id, "max")]/tbody/tr[3]/td[3]/span[1]/text()').get(), stat.xpath('.//table[contains(@id, "max")]/tbody/tr[4]/td[3]/span[1]/text()').get()],92                        "DEF": [stat.xpath('.//table[contains(@id, "max")]/tbody/tr[2]/td[4]/span[1]/text()').get(), stat.xpath('.//table[contains(@id, "max")]/tbody/tr[3]/td[4]/span[1]/text()').get(), stat.xpath('.//table[contains(@id, "max")]/tbody/tr[4]/td[4]/span[1]/text()').get()],93                        "RES": [stat.xpath('.//table[contains(@id, "max")]/tbody/tr[2]/td[5]/span[1]/text()').get(), stat.xpath('.//table[contains(@id, "max")]/tbody/tr[3]/td[5]/span[1]/text()').get(), stat.xpath('.//table[contains(@id, "max")]/tbody/tr[4]/td[5]/span[1]/text()').get()]94                    },95                    "Weapon" : {96                        "HP": [stat.xpath('.//table[contains(@id, "max")]/tbody/tr[2]/td[1]/span[2]/text()').get(), stat.xpath('.//table[contains(@id, "max")]/tbody/tr[3]/td[1]/span[2]/text()').get(), stat.xpath('.//table[contains(@id, "max")]/tbody/tr[4]/td[1]/span[2]/text()').get()],97                        "ATK": [stat.xpath('.//table[contains(@id, "max")]/tbody/tr[2]/td[2]/span[2]/text()').get(), stat.xpath('.//table[contains(@id, "max")]/tbody/tr[3]/td[2]/span[2]/text()').get(), stat.xpath('.//table[contains(@id, "max")]/tbody/tr[4]/td[2]/span[2]/text()').get()],98                        "SPD": [stat.xpath('.//table[contains(@id, "max")]/tbody/tr[2]/td[3]/span[2]/text()').get(), stat.xpath('.//table[contains(@id, "max")]/tbody/tr[3]/td[3]/span[2]/text()').get(), stat.xpath('.//table[contains(@id, "max")]/tbody/tr[4]/td[3]/span[2]/text()').get()],99                        "DEF": [stat.xpath('.//table[contains(@id, "max")]/tbody/tr[2]/td[4]/span[2]/text()').get(), stat.xpath('.//table[contains(@id, "max")]/tbody/tr[3]/td[4]/span[2]/text()').get(), stat.xpath('.//table[contains(@id, "max")]/tbody/r[4]/td[4]/span[2]/text()').get()],100                        "RES": [stat.xpath('.//table[contains(@id, "max")]/tbody/tr[2]/td[5]/span[2]/text()').get(), stat.xpath('.//table[contains(@id, "max")]/tbody/tr[3]/td[5]/span[2]/text()').get(), stat.xpath('.//table[contains(@id, "max")]/tbody/tr[4]/td[5]/span[2]/text()').get()]101                    }102                }103            })...xpath_util.js
Source:xpath_util.js  
1// Copyright 2013 Google Inc.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7//      http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14/**15 * @fileoverview A collection of JavaScript utilities used to simplify working16 * with xpaths.17 * @author clchen@google.com (Charles L. Chen)18 */19goog.provide('cvox.XpathUtil');20/**21 * Utilities for simplifying working with xpaths22 * @constructor23 */24cvox.XpathUtil = function() {25 };26/**27 * Mapping for some default namespaces.28 * @const29 * @private30 */31cvox.XpathUtil.nameSpaces_ = {32  'xhtml' : 'http://www.w3.org/1999/xhtml',33  'mathml': 'http://www.w3.org/1998/Math/MathML'34};35/**36 * Resolve some default name spaces.37 * @param {string} prefix Namespace prefix.38 * @return {string} The corresponding namespace URI.39 */40cvox.XpathUtil.resolveNameSpace = function(prefix) {41  return cvox.XpathUtil.nameSpaces_[prefix] || null;42};43/**44 * Given an XPath expression and rootNode, it returns an array of children nodes45 * that match. The code for this function was taken from Mihai Parparita's GMail46 * Macros Greasemonkey Script.47 * http://gmail-greasemonkey.googlecode.com/svn/trunk/scripts/gmail-new-macros.user.js48 * @param {string} expression The XPath expression to evaluate.49 * @param {Node} rootNode The HTML node to start evaluating the XPath from.50 * @return {Array} The array of children nodes that match.51 */52cvox.XpathUtil.evalXPath = function(expression, rootNode) {53  try {54    var xpathIterator = rootNode.ownerDocument.evaluate(55      expression,56      rootNode,57      cvox.XpathUtil.resolveNameSpace,58      XPathResult.ORDERED_NODE_ITERATOR_TYPE,59      null); // no existing results60  } catch (err) {61    return [];62  }63  var results = [];64  // Convert result to JS array65  for (var xpathNode = xpathIterator.iterateNext();66       xpathNode;67       xpathNode = xpathIterator.iterateNext()) {68    results.push(xpathNode);69  }70  return results;71};72/**73 * Given a rootNode, it returns an array of all its leaf nodes.74 * @param {Node} rootNode The node to get the leaf nodes from.75 * @return {Array} The array of leaf nodes for the given rootNode.76 */77cvox.XpathUtil.getLeafNodes = function(rootNode) {78  try {79    var xpathIterator = rootNode.ownerDocument.evaluate(80      './/*[count(*)=0]',81      rootNode,82      null, // no namespace resolver83      XPathResult.ORDERED_NODE_ITERATOR_TYPE,84      null); // no existing results85  } catch (err) {86    return [];87  }88  var results = [];89  // Convert result to JS array90  for (var xpathNode = xpathIterator.iterateNext();91       xpathNode;92       xpathNode = xpathIterator.iterateNext()) {93    results.push(xpathNode);94  }95  return results;96};97/**98 * Returns whether or not xpath is supported.99 * @return {boolean} True if xpath is supported.100 */101cvox.XpathUtil.xpathSupported = function() {102  if (typeof(XPathResult) == 'undefined') {103    return false;104  }105  return true;106};107/**108 * Given an XPath expression and rootNode, it evaluates the XPath expression as109 * a boolean type and returns the result.110 * @param {string} expression The XPath expression to evaluate.111 * @param {Node} rootNode The HTML node to start evaluating the XPath from.112 * @return {boolean} The result of evaluating the xpath expression.113 */114cvox.XpathUtil.evaluateBoolean = function(expression, rootNode) {115  try {116    var xpathResult = rootNode.ownerDocument.evaluate(117        expression,118        rootNode,119        cvox.XpathUtil.resolveNameSpace,120        XPathResult.BOOLEAN_TYPE,121        null); // no existing results122  } catch (err) {123    return false;124  }125  return xpathResult.booleanValue;126};127/**128 * Given an XPath expression and rootNode, it evaluates the XPath expression as129 * a string type and returns the result.130 * @param {string} expression The XPath expression to evaluate.131 * @param {Node} rootNode The HTML node to start evaluating the XPath from.132 * @return {string} The result of evaluating the Xpath expression.133 */134cvox.XpathUtil.evaluateString = function(expression, rootNode) {135  try {136    var xpathResult = rootNode.ownerDocument.evaluate(137        expression,138        rootNode,139        cvox.XpathUtil.resolveNameSpace,140        XPathResult.STRING_TYPE,141        null); // no existing results142  } catch (err) {143    return '';144  }145  return xpathResult.stringValue;...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
