Selenium 无法使用xpath定位元素
我对Selenium非常陌生,只是学到了一些东西并尝试自动化。无法在Selenium webdriver中找到以下元素:Selenium 无法使用xpath定位元素,selenium,xpath,webdriver,Selenium,Xpath,Webdriver,我对Selenium非常陌生,只是学到了一些东西并尝试自动化。无法在Selenium webdriver中找到以下元素: <div class="navBg withSubMenu"> <table id="topnav" class="navTable" cellspacing="0" cellpadding="0" style="-moz-user-select: none; cursor: default;"> <tbody>
<div class="navBg withSubMenu">
<table id="topnav" class="navTable" cellspacing="0" cellpadding="0" style="-moz-user-select: none; cursor: default;">
<tbody>
<tr>
<td class="logoCell navCell" valign="top">
<td class="navItem navCell relative selected">
<td class="navItem navCell relative notSelected">
<a class="content tasks" href="/tasks/otasklist.do">
<div class="label" style="z-index:155; ">TASKS</div>
<div class="img"> </div>
</a>
</td>
<td class="navItem navCell relative notSelected">
<a class="content reports" href="/reports/reports.do">
</td>
<td class="navItem navCell relative notSelected">
<td class="menuCell navCell" valign="top">
</tr>
<tr class="secondLevelRow">
</tbody>
</table>
任何人都可以帮助我
另外,请推荐一些网站或链接,以了解更多有关定位器的信息,尤其是xpath。我试了几次,但没有深入
提前感谢。开始
包含和小写c
:
driver1.findElement(By.xpath("//*[contains(@class, 'content tasks')]")).click();
driver1.findElement(By.xpath(“//a[@class='content tasks']”)。单击();
,也请推荐一些网站或链接,以了解有关定位器(尤其是xpath)的更多信息。我试了几次,但没有深入研究。@Harish,如果有帮助,请回答这个问题。谢谢,我喜欢。这是官方的参考资料,也很平易近人。例如,请参见中列出的示例。
driver1.findElement(By.xpath("//*[contains(@class, 'content tasks')]")).click();
<a class="content tasks" href="/tasks/otasklist.do">
driver1.findElement(By.xpath("//a[@class='content tasks']")).click();