我一直在为一个在IE11中运行的简单python脚本而挣扎,因为某些原因,它无法找到任何elemnt,但是通过在它工作的java代码中设置一些所需的功能:
System.setProperty("webdriver.ie.driver", "C:\\Python27\\IEDriverServer.exe");
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
WebDriver driver = new InternetExplorerDriver(ieCapabilities);//
driver.navigate().to("http://www.google.com");
WebElement search =driver.findElement(By.name("q"));
search.sendKeys("selenium");
search.submit();
但是,由于我已经用python编写了测试,所以我希望在python中使用相同的方法:
^{pr2}$但是由于某些原因,selenium仍然无法找到搜索栏,所以我猜我用python编写的对应项是不对的,有人能给我指出正确的方向吗?在
你必须注意以下几个事实:
DesiredCapabilities.INTERNETEXPLORER
,你需要使用DesiredCapabilities.INTERNETEXPLORER.copy()
executablePath
不是任何有效参数。而是在初始化WebDriver/WebClient时传递参数executable_path
。在introduceFlakinessByIgnoringSecurityDomains();
,根据You're Doing It Wrong: IE Protected Mode and WebDriver@JimEvans再次明确指出,添加INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS
可能会使您越过初始异常,并允许测试在大多数情况下无事故运行。然而,使用此功能并不能解决根本问题。如果一个保护模式边界被跨越,可能会发生非常意外的行为,包括挂起,元素位置不工作,以及点击未传播。在当您发送字符序列到谷歌搜索框而不是
presence_of_element_located()
方法时,请使用element_to_be_clickable()
方法。以下是您自己的代码,并进行了一些修改:
浏览器快照:
这里有关于Unexpected error launching Internet Explorer. IELaunchURL() returned HRESULT 80070012 with Selenium 3.13.0: IEDriverServer_x64_3.13.0的详细讨论
相关问题 更多 >
编程相关推荐