admin管理员组文章数量:1654038
Using XPath to identify Web objects from Selenium WebDriver
XPath can be used by following methods,In the below example, to find a web object of <input> tag category with name as deposit, XPath can be formed as XPath( "//Input[@name='deposit']") and C# statement for the same can be formed as driver.FindElement( By.XPath( "//Input[@name='deposit']"))
Screen reference
HTML reference <tr> <td width="30%" nowrap="" align="left"> <input type="text class=" οnkeyup="javascript:doCheckTBox(this,2,2)" size="8" value="2000000" name="deposit" flat"="" style="text-align: right;"> </td> </tr>
2. To find a web object by class attribute
driver.FindElement( By.XPath( "//Tag[@class='class-name']"))
In the below example, to find a web object of <td> tag category with class as navtab_selected, XPath can be formed as XPath( "//td[@class='navtab_selected']") and C# statement for the same can be formed as driver.FindElement( By.XPath( "//td[@class='navtab_selected']"))
Screen reference HTML reference <td align="center" class="navtab_selected"> <a href="/">Home</a> </td>
3. To find a web object by multiple attributes
driver.FindElement( By.XPath( "//Tag[@type='type-name' and @name='name']"))
In the below example, to find a web object of <input> tag category with type as button and name as btnGo, XPath can be formed as XPath( "//input[@type='button' and @name='btnGo']") and C# statement for the same can be formed as driver.FindElement( By.XPath( "//input[@type='button' and @name='btnGo']" ))
Screen reference
HTML reference <input type="button" οnclick="javascript: doSubmitCompareRateProduct()" value="Go" class="flat" name="btnGo">
4. To find a web object by using the contained text
I have a well formed XHTML page. I want to find the web object with URL, for which I have the text that is linked. Example
<a href="http://TestURL">Text of the URL</a>
The
XPath expression to find the URL link with text as
Text of the URL is
//a[text()='Text of the URL']
本文标签: webidentifyXPathWebdriverselenium
版权声明:本文标题:Using XPath to identify Web objects from Selenium WebDriver 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dongtai/1729650845a1209020.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论