java - 无法通过 Selenium 和 WebDriver 定位元素

标签 java selenium selenium-webdriver xpath css-selectors

我正在尝试单击“保存”按钮。但我无法单击它,因为在按钮之前它有“::before”。 我尝试使用 cssSelector 和 xpath 进行定位。但我无法找到它。有人可以帮助我吗?

enter image description here

最佳答案

您尝试定位的元素位于模态对话框内,因此您必须引发WebDriverWait才能使该元素可单击,并且您可以使用以下选项之一:

  • css选择器:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.modal-footer button.btn.btn-default#save"))).click();
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='modal-footer']//button[@class='btn btn-default' and @id='save']"))).click();
    

关于java - 无法通过 Selenium 和 WebDriver 定位元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50258137/

相关文章:

java - 从 YAML 文件 : No content to map due to end-of-input 读取时出现 JsonMappingException

selenium - 无效参数异常 : invalid argument: Unsupported locator strategy: -custom error with Appium using Selenium ChromeDriver and Chrome

javascript - elementExplorer 字符转义在 Protractor 1.8.0 和 2.0.0 上回归?

javascript - 如何打破 promise 链

java - 使用StanfordCoreNLP提取两个实体之间的关系

java - BLE 扫描不能在后台使用 android pie 中的 Scanfilters 工作?

Java语句,处理优先级("dangling else")

c# - 如何配置自动化测试以在不同的时间表中运行?

r - session 未创建 : This version of ChromeDriver only supports Chrome version 74 error with ChromeDriver Chrome using Selenium

python - 在几次成功的 Selenium Geckodriver 任务后连接被拒绝(操作系统错误 111)(Python)