硒web驱动程序。无法通过ID找到元素,xpath
问题描述:
我有以下代码,我试图使用findElement By.xpath或By.id来恶化元素,如何找不到元素。硒web驱动程序。无法通过ID找到元素,xpath
,即时通讯期待的元素是这个类里面:
<a class="menulink" id="menu_link_200" onClick="showSelectedMenu('200','');openFrame('mainFrame','Mediator.jsp?gotouri=ShowFindConsumer.do&menutype=customer')" >
Customers
</a>
</td>
</tr>
<tr>
<td colspan="2" class="separateline"></td>
</tr>
</span>
答
尝试
//Using LinkText
driver.FindElement(By.LinkText("Customers"));
//Using Class Name
driver.FindElement(By.ClassName("menulink"));
//Using CSS Selector
driver.FindElement(By.CssSelector("a#menu_link_200"));
driver.FindElement(By.CssSelector("a.menulink"));
让我知道,如果没有这些作品。可能会分享完整的HTML代码会有所帮助。
答
你可以截取你正在寻找什么?看起来这个元素在你点击的时候会被填充。点击甚至调用“openFrame”函数(我也需要看代码)。因此,如果我要回答你盲目折叠,我会说你需要先调用。点击链接 - 也许通过做driver.findElement(By.linkText(“Customers”))。点击( ); - 然后查看添加的HTML内容。
答
的事情是,我的代码是一个框架,所以我用:
driver.switchTo().frame("menuFrame");
现在,它的工作。
尝试按类找到它(driver.FindElement(By.ClassName(“menulink”))) –
你能分享你的代码吗?因为HTML看起来很简单。或者是动态生成的Id或类似的? – amitbobade