Selenium Webdriver 通过带有字符串引号的 Xpath 问题查找元素
Selenium Webdriver find element by Xpath problem with String quotation marks
这是我的代码:
var loginButton = driver.FindElement(By.XPath("//*[@id="login - view"]/form/div[3]/button"));
我已经看到了post:
但这对我没有帮助
引号是问题所在
id 属性 值是否正确? “-”前后有一些空格
尝试使用单引号将 id 值放入字符串中。
var loginButton = driver.FindElement(By.XPath("//*[@id='login - view']/form/div[3]/button"));
根据您在此处添加的内容:
<button type="submit" aria-label="Login button" class="btn btn-large p-x-2 btn-inverse" disabled="">Log In</button>
这个 disabled 属性导致了问题,因为它使元素(您猜对了)被禁用了!见 - 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']
是否还有其他未禁用的登录按钮?
这是我的代码:
var loginButton = driver.FindElement(By.XPath("//*[@id="login - view"]/form/div[3]/button"));
我已经看到了post:
但这对我没有帮助
引号是问题所在
id 属性 值是否正确? “-”前后有一些空格
尝试使用单引号将 id 值放入字符串中。
var loginButton = driver.FindElement(By.XPath("//*[@id='login - view']/form/div[3]/button"));
根据您在此处添加的内容:
<button type="submit" aria-label="Login button" class="btn btn-large p-x-2 btn-inverse" disabled="">Log In</button>
这个 disabled 属性导致了问题,因为它使元素(您猜对了)被禁用了!见 - 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']
是否还有其他未禁用的登录按钮?