【问题标题】:how to add explicit wait in drop down in selenium which is dependent on another dropdown?如何在依赖于另一个下拉列表的 selenium 下拉列表中添加显式等待?
【发布时间】:2017-07-03 18:11:02
【问题描述】:

如何使用 selenium 在下拉列表中添加显式等待,直到找到文本?

【问题讨论】:

  • 我想添加明确的等待,直到它找到“fa”
  • 为什么您需要等待option- 它已经在页面源中?您的代码有任何异常吗?您在查找 select 元素时遇到问题吗?
  • 我有 2 个下拉菜单。第二个下拉菜单取决于第一个下拉菜单。所以需要添加一些等待时间
  • 那么维基页面只是举例?您可以为下拉元素或目标页面URL 分享确切的HTML 吗?
  • 我已经添加了图片。你可以看到以下下拉菜单被禁用,直到第一个被启用

标签: java selenium selenium-webdriver automation appium


【解决方案1】:

试试下面的代码。

WebDriverWait wait = new WebDriverWait(driver, 15);          //add Explicit Wait
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("Your xpath"))));

driver.findElement(By.xpath("Your xpath")).click();   //After Explicit Wait Click on WebElement

【讨论】:

  • 如果您的回答是helpful,请将此回答标记为Accepted
【解决方案2】:
WebDriver wait = new WebDriver(Driver, Seconds);
boolean status; 

status = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(""))) != null;

【讨论】:

    【解决方案3】:
    public boolean waitForElement( String element, int timeout) {
            WebDriverWait wait = new WebDriverWait(appiumDriver, timeout/1000);
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(element)));
            return true;
        }
    
    element is the xpath.
    
    and when you run this function it will wait for timeout(millisecond ) max for the element to appear .
    if the element comes early than it will break and return true which means element is present.
    

    【讨论】:

    • 请检查更新后的问题
    猜你喜欢
    • 1970-01-01
    • 2021-03-12
    • 1970-01-01
    • 2021-05-26
    • 2019-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多