簡體   English   中英

無法點擊下拉菜單

[英]Not able to click dropdown

我是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();

要單擊“下拉列表”,請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();

讓我知道這是否回答了您的問題。

嘗試這個

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")));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM