在Selenium执行脚本过程中经常会遇到一些异常,一下是部分小结:
ElementNotSelectableException :元素不能选择异常
ElementNotVisibleException :元素不可见异常
NoSuchAttributeException :没有这样属性异常
NoSuchElementException:没有该元素异常
NoSuchFrameException :没有该frame异常
TimeoutException : 超时异常
Element not visible at this point :在当前点元素不可见
如何处理不受信任的证书问题:
(1)火狐:
/ 创建firefoxprofile
FirefoxProfile profile=new FirefoxProfile();
// 点击继续浏览不安全的网站
profile.setAcceptUntrustedCertificates(true);
// 使用带条件的profile去创建一个driver对象
WebDriver driver=new FirefoxDriver(profile);
(2)谷歌:
// 创建类DesiredCapabilities的对象
DesiredCapabilities cap=DesiredCapabilities.chrome();
// 设置ACCEPT_SSL_CERTS 变量值为true
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
// 新建一个带capability的chromedriver对象
WebDriver driver=new ChromeDriver(cap);