Javascript 硒:“;在“点”处不可单击;如何等待所有脚本加载完毕
我有3次等待:Javascript 硒:“;在“点”处不可单击;如何等待所有脚本加载完毕,javascript,java,jquery,selenium,webdriver,Javascript,Java,Jquery,Selenium,Webdriver,我有3次等待: wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='pagecontrols']/input[1]"))); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='pagecontrols']/input[1]"))); wait.until(ExpectedConditions.visibility
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='pagecontrols']/input[1]")));
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='pagecontrols']/input[1]")));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='pagecontrols']/input[1]")));
对于相同的元素,但在等待之后,当我要单击
driver.findElement(By.xpath("//*[@id='pagecontrols']/input[1]")).click();
我有:
“元素(…)在点处不可单击”
我试图通过添加此部分来等待JavaScript完全加载
public void waitForLoad(WebDriver driver)
{
ExpectedCondition<Boolean> pageLoadCondition = new ExpectedCondition<Boolean>()
{
public Boolean apply(WebDriver driver)
{
return ((JavascriptExecutor)driver).executeScript("return document.readyState").equals("complete");
}
};
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(pageLoadCondition);
}
public void waitForLoad(WebDriver驱动程序)
{
ExpectedCondition pageLoadCondition=新的ExpectedCondition()
{
公共布尔应用(WebDriver驱动程序)
{
return((JavascriptExecutor)driver.executeScript(“return document.readyState”).equals(“complete”);
}
};
WebDriverWait wait=新的WebDriverWait(驱动程序,30);
等待.直到(pageLoadCondition);
}
但是这不起作用(在不同的地方提供帮助,所以通常在某些情况下提供帮助),也许我做错了什么?
我想我也应该等待jQuery,但老实说,我知道怎么做(我已经找到了一些解决方案,但它们对我不起作用)
线程“main”org.openqa.selenium.WebDriverException中的异常:未知错误:元素在点(1397,97)处不可单击。其他元素将收到单击:
(会话信息:chrome=55.0.2883.87)
(驱动程序信息:chromedriver=2.27.440174(E97A722CAFC2D3A8B807EE115BFB307F7D2CFD9),平台=Windows NT 6.1.7601 SP1 x8664)(警告:服务器未提供任何堆栈跟踪信息)
命令持续时间或超时:149毫秒
构建信息:版本:“未知”,版本:“1969d75”,时间:“2016-10-18 09:43:45-0700”
系统信息:主机:'BTIS1000062581',ip:'x.x.x.x',os.name:'Windows 7',os.arch:'x86',os.version:'6.1',java.version:'1.8.0_20'
驱动程序信息:org.openqa.selenium.chrome.ChromeDriver
功能[{applicationCacheEnabled=false,rotatable=false,mobileEmulationEnabled=false,networkConnectionEnabled=false,chrome={chromedriverVersion=2.27.440174(E97A72CAAFC2D3A8B807EE115BFB307F7D2CFD9),userDataDir=C:\Users\user\AppData\Local\Temp\scoped\U dir7068\U 2467},takesHeapSnapshot=true,pageLoadStrategy=normal,databaseEnabled=false,handlesAlerts=true,hasTouchScreen=false,version=55.0.2883.87,platform=XP,browserConnectionEnabled=false,nativeEvents=true,acceptSslCerts=true,locationContextEnabled=true,WebStorage=true,browserName=chrome,TakesScreensShot=true,javascriptEnabled=true,CsselectorsEnabled=true,意外的alertbehaviour=}]
会话ID:e9c9bf2150b10d2865e7a117c1c9e739
位于sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)
位于sun.reflect.NativeConstructorAccessorImpl.newInstance(未知源)
位于sun.reflect.delegatingConstructor或AccessorImpl.newInstance(未知源)
位于java.lang.reflect.Constructor.newInstance(未知源)
位于org.openqa.selenium.remote.ErrorHandler.CreateTrowable(ErrorHandler.java:216)
位于org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
位于org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:635)
位于org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:274)
在org.openqa.selenium.remote.RemoteWebElement.click上(RemoteWebElement.java:84)
位于automationFramework.FirstTestCase.main(FirstTestCase.java:201)
还有一件事:当我添加
睡眠(500);
在单击元素之前,它正在工作,但我想消除这些睡眠您应该等待拦截单击的元素消失:
new WebDriverWait(driver, 10).until(ExpectedConditions.invisibilityOfElementLocated(By.xpath('//div[@class="blockUI blockOverlay"]')));
driver.findElement(By.xpath("//input[@value='Add user']")).click();
我相信在这里添加等待页面加载应该可以很好地工作:
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
避免这种“冒烟”用户界面拦截器的唯一真正有效的方法是使用Thread.sleep();3000毫升,瞧 您应该期望块ui在单击操作或任何其他操作之前消失。 例如:
public void aguardaBlockUi(){
WebElement elementBlock = (findElement(By.xpath("//div[@class='blockUI blockOverlay']")));
WebDriverWait wait = new WebDriverWait( driver, 180 );
wait.until(ExpectedConditions.invisibilityOf(elementBlock ));
}
我将webdriver子类化以拦截。通过*()查找元素并延迟,直到所有blockUI div都消失。这使我的主代码更清晰
从selenium.webdriver导入Chrome
从selenium.webdriver.common.by导入
从selenium.webdriver.support将预期的_条件导入为EC
从selenium.webdriver.support.ui导入WebDriverWait
类别MyChrome(Chrome):
def find_元素(self,by=by.ID,value=None):
#等待jQuery BlockUI插件删除所有元素
#注意:driver=super()以避免递归错误
WebDriverWait(super(),10)。直到\u未(EC.presence\u\u元素\u位于(
(By.CSS_选择器,“div.blockUI”),
))
return super().find_元素(by=by,value=value)
粘贴此处出现的整个异常。如果要单击的元素被其他元素阻挡,则可能发生这种情况。你可以发布一个你正在测试的网页的样本吗?这个网页只有在我的网络中才可以访问。它正在工作,但是它需要很多时间。老实说,我不知道发生了什么,它应该每500毫秒检查一次这个元素“//div[@class='blockUI blockOverlay']”,最多检查10次,但对我来说,这需要更长的时间5s@Krzysztof然后将新的WebDriverWait(driver,10)更改为新的WebDriverWait(driver,5)仍然相同-我试图更改它,但没有结果System.out.println(“等待前”+System.currentTimeMillis();
新建WebDriverWait(驱动程序,5)。直到(ExpectedConditions.invisibilityOfElementLocated(By.xpath(//div[@class='blockUI blockOverlay']);
System.out.println(“等待后”+System.currentTimeMillis())
在等待1485261322976之前,在等待1485261335940之后,我使用这个,但是没有结果
public void aguardaBlockUi(){
WebElement elementBlock = (findElement(By.xpath("//div[@class='blockUI blockOverlay']")));
WebDriverWait wait = new WebDriverWait( driver, 180 );
wait.until(ExpectedConditions.invisibilityOf(elementBlock ));
}