【发布时间】:2018-07-19 06:53:43
【问题描述】:
这是我的 HTML 片段:
HTML:
<button class="confirm" tabindex="1" style="display: inline-block; background-color: rgb(140, 212, 245); box-shadow: rgba(140, 212, 245, 0.8) 0px 0px 2px, rgba(0, 0, 0, 0.05) 0px 0px 0px 1px inset;">OK</button>
我试图通过 Selenium WebDriver 单击确定按钮,但它给了我:错误:
no such element: Unable to locate element: {"method":"cssselector","selector":"button[class='confirm']"}
目前我在 Selenium 中使用此代码:
driver.findElement(By.cssSelector("button[class='confirm']"));
【问题讨论】:
-
确保您的按钮不在某个 iframe 中。并尝试等待按钮可见。
-
分享 button 的完整 HTML,并检查元素是否在任何 iframe 内
标签: java selenium selenium-webdriver xpath css-selectors