簡體   English   中英

Selenium WebDriver-即使存在元素也會出現NoSuchElementException錯誤

[英]Selenium WebDriver - Getting NoSuchElementException error even element is present

我試圖單擊應用程序中的下拉框,而Xpath是: //*[@id='sel2O5_chzn']/a但是,當我嘗試單擊它時,應用程序中出現NoSuchElementException Even元素。 在IE中嘗試過,Chrome和Firefox仍然面臨相同的問題

driver.findElement(By.xpath("//*[@id='sel2T1_chzn']/a")).click();

也嘗試過以下方式,但沒有運氣。 獲取相同的NoSuchElementException

Select sel = new Select(driver.findElement(By.xpath("//*[@id='sel2T1_chzn']")));
sel.selectByIndex(1);

請幫助我解決這個問題

使用explicit等待,它使您能夠等待WebDriver 找到元素, 是您可以使用的ExpectedConditions的列表

WebElement myDynamicElement = (new WebDriverWait(driver, 10))
  .until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='sel2T1_chzn']")));
myDynamicElement.click();

暫無
暫無

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

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