2017-06-06 52 views
1

我在硒一個新的學習和嘗試點擊下拉填充列表,但它不斷給我運行時異常:線程「main」 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(); 
+1

哪些元素是你想點擊的網頁?謝謝 – DebanjanB

回答

0

要單擊下拉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(); 

讓我知道如果這個回答你的問題。

+0

非常好!現在工作。謝謝Deb – Ref

+0

@Ref很高興能夠幫助你。您可以通過點擊答案旁邊的勾號來接受答案,就在投票上方/下方箭頭下方,勾號變成綠色?謝謝 – DebanjanB

+0

@ Deb- done.Thanks – Ref

0

嘗試這個

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

OR

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