HTML:
<label for="header-nav-toggle" class="header-nav__toggle">Menu</label>
在单击网页中的菜单时,将显示带有SignOut
选项的用户。
如何为此操作编写XPath?
对于XPath
$x("//*[@id='root']/div/main/div/header/div/label")
在Chrome中-我得到的Devtools-Console
[label.header-nav__toggle]
0: label.header-nav__toggle
length: 1
__proto__: Array(0)
需要选择0:值。遇到类似
的错误org.openqa.selenium.WebDriverException: unknown error:
Element <label for="header-nav-toggle" class="header-nav__toggle">...</label>
is not clickable at point (1236, 52). Other element would receive the click:
<div class="sc-ifAKCX cHaoWT" data-delay="250"></div>
答案 0 :(得分:0)
您可以根据给定的HTML和Exception类型引用此解决方案:
Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.xpath("//label[@class='header-nav__toggle' and contains(text(),'Menu')]"))).click().perform();
答案 1 :(得分:0)