SeleniumWebdriver使用字符串引号通过Xpath问题查找元素



这里是我的代码:

var loginButton = driver.FindElement(By.XPath("//*[@id="login - view"]/form/div[3]/button"));

我已经看到了这篇文章:在Selenium中通过xpath查找包含引号的文本

但这对我没有帮助

引号是问题

尝试使用单引号将id值放入字符串中。

var loginButton = driver.FindElement(By.XPath("//*[@id='login - view']/form/div[3]/button"));

id属性值正确吗?它在"-"前后有一些空格

基于您在此处添加的内容:

<button type="submit" aria-label="Login button" class="btn btn-large p-x-2 btn-inverse" disabled="">Log In</button>

这个被禁用的属性导致了问题,因为它使元素,你猜对了,被禁用了!请参阅-https://www.w3schools.com/tags/att_disabled.asp

如果你去掉它,它看起来像这样:

<button type="submit" aria-label="Login button" class="btn btn-large p-x-2 btn-inverse">Log In</button>

然后你可以使用下面的,它会很好。

//button[text()='Log In']

是否有其他未禁用的登录按钮?

最新更新