You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Eclipse/Java环境下用Selenium点击Done按钮?

在Eclipse/Java+Selenium环境中点击Done按钮的解决办法

我在Eclipse/Java结合Selenium的环境下,想点击界面上标注“Done”的确认按钮,已经试过这段代码但没成功:

driver.findElement(By.cssSelector("button[aria-label='Done. Search for round trip flights, departing on March 15, 2025 and returning on April 15, 2025']")).click();

试试这些调整方法

  • 别用带动态日期的定位符:你写的aria-label里包含了具体出发和返程日期,这类内容是动态变化的,换个只匹配固定内容的选择器,比如只抓包含"Done"的按钮:
    driver.findElement(By.cssSelector("button[aria-label*='Done']")).click();
    
  • 加个等待确保元素能点:页面加载慢的话,直接点会报错,加个显式等待等元素可点击:
    WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
    WebElement doneBtn = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("button[aria-label*='Done']")));
    doneBtn.click();
    
  • 换其他定位方式:要是上面的还不行,试试别的路子:
    • 按按钮文本找(如果按钮上显示的是"Done"):
      driver.findElement(By.xpath("//button[text()='Done']")).click();
      
    • 按class属性找(查看元素的class值,选一个稳定的填进去):
      driver.findElement(By.className("替换成实际的class名称")).click();
      

内容的提问来源于stack exchange,提问作者Tanguy MP

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 12:29:57