Selenium + Java系列三:常见报错

报错一、Timed out receiving message from renderer
解决方案:
该问题可以pageLoadTimeout来解决 加载策略不要设置为none

报错二、org.openqa.selenium.ElementNotInteractableException
解决方案:
It could be because of two reasons.

  1. Your button element is visible but not yet clickable. If that is the case use wait condition.
    WebDriverWait myWaitVar = new WebDriverWait(driver,20);
    WebElement el = myWaitVar.until(ExpectedConditions.elementToBeClickable(betting.findElements(By.xpath("//*[@id=‘flex-menu’]//ul//li//a")).get(0)));
    el.click();
  2. If element is hidden/overlapped by some other element use JavascriptExecutor
    WebDriverWait myWaitVar = new WebDriverWait(driver,20);
    WebElement el = myWaitVar.until(ExpectedConditions.elementToBeClickable(betting.findElements(By.xpath("//*[@id=‘flex-menu’]//ul//li//a")).get(0)));
    ((JavascriptExecutor)driver).executeScript(“arguments[0].click()”, el);

报错三、selenium点击失效
解决方案:
点击上一层元素,定位焦点

报错四、selenium报错Unable to find element on closed window
解决方案:

Way 2: To set a registry entry on the target computer:
For IE 11 only, you will need to set a registry entry on the target computer so that the driver can maintain a connection to the instance of Internet Explorer it creates.

For 32-bit Windows: The key you must examine in the registry editor is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE.

For 64-bit Windows: The key is HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE.

Please note that the FEATURE_BFCACHE subkey may or may not be present, and should be created if it is not present. Important: Inside this key, create a DWORD value named iexplore.exe with the value of 0.

报错四、selenium在IE环境下,不支持可视化查找
问题:selenium 不支持IE条件下滚动条滚动,不支持视野之外元素操作
解决方案:
1、用js移动滚动条

  //移动到元素element对象的“顶端”与当前窗口的“顶部”对齐 
   ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView();", element); 
   ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element); 
    
   //移动到元素element对象的“底端”与当前窗口的“底部”对齐 
   ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(false);", element); 
    
   //移动到页面最底部 
   ((JavascriptExecutor) driver).executeScript("window.scrollTo(0, document.body.scrollHeight)"); 
    
   //移动到指定的坐标(相对当前的坐标移动) 
   ((JavascriptExecutor) driver).executeScript("window.scrollBy(0, 700)"); 
   Thread.sleep(3000); 
   //结合上面的scrollBy语句,相当于移动到700+800=1600像素位置 
   ((JavascriptExecutor) driver).executeScript("window.scrollBy(0, 800)"); 
    
   //移动到窗口绝对位置坐标,如下移动到纵坐标1600像素位置 
   ((JavascriptExecutor) driver).executeScript("window.scrollTo(0, 1600)"); 
   Thread.sleep(3000); 
   //结合上面的scrollTo语句,仍然移动到纵坐标1200像素位置 
   ((JavascriptExecutor) driver).executeScript("window.scrollTo(0, 1200)"); 

2、如果js不生效,则可以先用element.sendkeys(""),焦点转移到这个元素,然后操作

报错五、WebDriverException: Message: Failed to navigate to http://10.1.96.59:9080. This usually means that a call to the COM method IWebBrowser2::Navigate2() failed."
解决方案:
开始->运行->输入gpedit.msc->管理模板->Windows 组件->Internet Explorer(单击选中)->阻止执行首次运行自定义设置”,选择“已启用”项,在“选择您的选择”下拉列表中选择“直接转到主页”。重新启动IE7就能解决问题

报错六、Command line server for the IE driver has stopped working error while running selenium test cases
解决方案:
Here some people managed to fix this problem by adding a new key in the registry. The new key is located in “HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main”, its name is “TabProcGrowth”, and its value is “0”.

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值