我正在尝试使用动态x路径查找元素,但我的代码不适用于该元素
<a href="/corporate-checkups/our-corporate-services.html" class="has-submenu" id="sm-15547263985364824-1" aria-haspopup="true" aria-controls="sm-15547263985364824-2" aria-expanded="false"><span class="sub-arrow">+</span>Our Services</a>
想通过使用Action类来选择子菜单,但是在这里我无法找到该元素
答案 0 :(得分:0)
To click()
on the sub-menu you can use either of the following Locator Strategies (Java Solution):
cssSelector:
driver.findElement(By.cssSelector("a.has-submenu[href='/corporate-checkups/our-corporate-services.html']>span.sub-arrow")).click();
xpath:
driver.findElement(By.xpath("//a[@class='has-submenu' and @href='/corporate-checkups/our-corporate-services.html']/span[@class='sub-arrow']")).click();
答案 1 :(得分:0)
基本上,您的定位器是一个链接,因此您必须使用非常简单的选项:
list
选择您认为哪个更适合您。