java - 无法在 Safari 13.0.4 中使用 Selenium 单击元素

标签 java selenium xpath css-selectors webdriverwait

org.openqa.selenium.WebElement.click()org.openqa.selenium.interactions.Actions.click() 等方法不会触发任何运行时出错,而且单击操作也不会发生。尝试使用 Javascript,但我尝试单击的元素似乎无法单击(在 Chrome 的开发人员工具中返回未定义)

这是该元素的 html

<div class="flatpickr-calendar animate showTimeInput arrowTop open" tabindex="-1" style="width: 245px; top: 719px; left: 1603.17px; right: auto;">
 <div class="flatpickr-months">...</div>
 <div class="flatpickr-innerContainer">
  <div class="flatpickr-rContainer">
  <div class="flatpickr-weekdays">...</div>
   <div class="flatpickr-days" tabindex="-1" style="width: 245px;">
    <div class="dayContainer">
     <span class="flatpickr-day " aria-label="December 29, 2019" tabindex="-1">29</span>
    </div>
   </div>
  </div>
 </div>
</div>

最佳答案

要单击该元素,您必须为 elementToBeClickable() 引发 WebDriverWait,并且您可以使用以下任一 Locator Strategies :

  • css选择器:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.dayContainer>span.flatpickr-day[aria-label='December 29, 2019']"))).click();
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='dayContainer']/span[@class='flatpickr-day ' and text()='29']"))).click();
    

关于java - 无法在 Safari 13.0.4 中使用 Selenium 单击元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59468360/

相关文章:

xpath - 网络抓取-从bandcamp.com获取项目标题

xml - xsl : sort nodes by values of subnode

Java框架创建简单的网站?

java - 什么是NullPointerException,我该如何解决?

Java发送和接收短信。免费短信网关?

java - 无法存储作业 : Driver's Blob representation is of an unsupported type: oracle. sql.BLOB [请参阅嵌套异常 : java. sql.SQLException

python - 为什么这个 python 代码可以在我的 XUbuntu (Ubuntu 20.04) 机器上运行,但不能在我的 Ubuntu 18.04 服务器上运行

performance - 使用 chrome 和 selenium 进行网络节流

java - Selenium By.xpath、By.linkName 以前可以工作,现在不再工作了

c# - Xpath标记化函数内部包含函数