Selenium Webdriver IE找不到元素 [英] Selenium Webdriver IE could not find element

查看:467
本文介绍了Selenium Webdriver IE找不到元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试导航到www.google.com,并使用带有Internet Explorer(IE)的Selenium Webdriver将一些输入发送到搜索框.

I am trying to navigate to www.google.com and send some inputs to search box using Selenium webdriver with Internet Explorer(IE).

static WebDriver webDriver = null;
static DesiredCapabilities IEDesiredCapabilities = DesiredCapabilities.internetExplorer();

System.setProperty("webdriver.chrome.driver", TestConstants.chromeDriverFilePath);
System.setProperty("webdriver.ie.driver", TestConstants.IEDriverFilePth);

IEDesiredCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
            true);
webDriver = new InternetExplorerDriver(IEDesiredCapabilities);
//webDriver = new ChromeDriver();

webDriver.navigate().to("http://www.google.com");
webDriver.findElement(By.name("q")).sendKeys("Venkatesh Kolisetty");
//webDriver.findElement(By.id("lst-ib")).sendKeys("Venkatesh Kolisetty");

当我使用Chrome时,这段代码运行得很好,但是当使用IE时,抛出org.openqa.selenium.NoSuchElementException.

This piece of code runs very well when i use Chrome, but throws org.openqa.selenium.NoSuchElementException when IE is used.

这将在由selenium打开的IE浏览器中打开所需的网页.问题是硒仅在使用IE时才能在页面加载后找不到任何元素.对于chrome,它会找到必需的元素.

This opens required web page in the IE browser which is opened by selenium. The problem is selenium is not able to find any element after page is loaded only when IE is used. For chrome, it finds required elements.

IEDesiredCapabilities

亲切地看到了提供程序化解决方案而不是手动更改Internet选项的可能性.

Kindly see the possibility of providing a programmatic solution instead of changing internet options manually.

推荐答案

添加了一些必需的功能后,问题已解决.

Issue resolved after adding some required capabilities.

IEDesiredCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
IEDesiredCapabilities.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, "http://www.google.com");
IEDesiredCapabilities.internetExplorer().setCapability("ignoreProtectedModeSettings", true);
IEDesiredCapabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
IEDesiredCapabilities.setJavascriptEnabled(true);
//IEDesiredCapabilities.setCapability("requireWindowFocus", true);
IEDesiredCapabilities.setCapability("enablePersistentHover", false);

IEDesiredCapabilities.setCapability("requireWindowFocus", true);是可选的

这篇关于Selenium Webdriver IE找不到元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆