我正在开展一个项目。我必须确定链接是否可点击。这是链接:
<div id="divMegamenu" class="column span_10_of_16 center_text mega_menu">
<a href="#" class="close_popup menu"></a>
<nav class="desktop_mega">
<ul>
<li id="g_women">
<span class="global_cat"><a href="http://www.forever21.com/Product/Category.aspx?br=f21&category=app-main">women</a></span>
以下是我写的xpath:
WebElement imgElement = driver.findElement(By.xpath("//nav[@id = 'desktop_mega']/ul/li[@id='g_women']/span[@id='global_cat']/a"));
但它继续提出没有这样的元素的例外
答案 0 :(得分:0)
desktop_mega
和global_cat
是类,而不是ID。将nav[@id = 'desktop_mega']
替换为nav[@class='desktop_mega']
,将span[@id='global_cat']
替换为span[@class='global_cat']
WebElement imgElement = driver.findElement(By.xpath("//nav[@class='desktop_mega']/ul/li[@id='g_women']/span[@class='global_cat']/a"));