Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Selenium WebDriver-即使存在元素,也会出现获取NoTouchElementException错误_Java_Selenium_Webdriver - Fatal编程技术网

Java Selenium WebDriver-即使存在元素,也会出现获取NoTouchElementException错误

Java Selenium WebDriver-即使存在元素,也会出现获取NoTouchElementException错误,java,selenium,webdriver,Java,Selenium,Webdriver,我试图单击应用程序中的下拉框,Xpath是:/*[@id='sel2O5\u chzn']/a 但是当我试着点击它的时候,我并没有感到意外 应用程序中存在偶数元素。在IE上试用,Chrome和Firefox仍然面临同样的问题 driver.findElement(By.xpath("//*[@id='sel2T1_chzn']/a")).click(); 也尝试过下面的方法,但没有运气。得到同样的非接触性异常 请帮助我解决此问题使用显式等待,它允许您等待通过WebDriver定位元素,并且是您

我试图单击应用程序中的下拉框,Xpath是:
/*[@id='sel2O5\u chzn']/a
但是当我试着点击它的时候,我并没有感到意外 应用程序中存在偶数元素。在IE上试用,Chrome和Firefox仍然面临同样的问题

driver.findElement(By.xpath("//*[@id='sel2T1_chzn']/a")).click();
也尝试过下面的方法,但没有运气。得到同样的非接触性异常


请帮助我解决此问题

使用
显式
等待,它允许您等待通过
WebDriver
定位元素,并且是您可以使用的
预期条件的列表

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

你能为下拉列表分享相关的HTML代码吗?有两种可能。1-显示元素需要时间。2-元素位于iframe或frame中。你能探索一下这两种可能性吗。如果你能提供HTML代码片段,它将帮助我们。
WebElement myDynamicElement = (new WebDriverWait(driver, 10))
  .until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='sel2T1_chzn']")));
myDynamicElement.click();