【问题标题】:Not able to click dropdown无法点击下拉菜单
【发布时间】:2017-06-06 22:00:20
【问题描述】:

我是 selenium 的新学习者,尝试单击下拉列表以填充列表,但它不断给我运行时异常:

线程“主”org.openqa.selenium.ElementNotVisibleException 中的异常: 元素当前不可见,因此可能无法与之交互)

请帮忙。下面是我正在执行的代码。

    WebDriver dr=new FirefoxDriver();
    dr.get("https://jqueryui.com/selectmenu/");
    dr.manage().window().maximize();
    dr.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    dr.switchTo().frame(dr.findElement(By.className("demo-frame")));
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("speed-       menu"))).click();

【问题讨论】:

  • 您试图点击网页上的哪个元素?谢谢

标签: java selenium-webdriver


【解决方案1】:

要点击下拉列表Select a speed,这里是您自己的代码,改动很小:

    System.setProperty("webdriver.gecko.driver", "C:\\your_directory\\geckodriver.exe");
    WebDriver dr=new FirefoxDriver();
    dr.get("https://jqueryui.com/selectmenu/");
    dr.manage().window().maximize();
    dr.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    dr.switchTo().frame(dr.findElement(By.className("demo-frame")));
    dr.findElement(By.xpath("//*[@id='speed-button']/span[@class='ui-selectmenu-text']")).click();

如果这能回答您的问题,请告诉我。

【讨论】:

    【解决方案2】:

    试试这个

    WebDriver driver = new FirefoxDriver();
    driver.get("https://jqueryui.com/selectmenu/");
    WebElement DynamicElement = (new WebDriverWait(driver, 10))
      .until(ExpectedConditions.presenceOfElementLocated(By.id("DynamicElement")));
    

    WebDriverWait wait = new WebDriverWait(driver, 10);
    WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("yourid")));
    

    【讨论】:

      猜你喜欢
      • 2017-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-01
      • 1970-01-01
      相关资源
      最近更新 更多