Selenium 2.0 WebDriver IE8 findelement by xpath ca

2019-02-13 21:44发布

When I run the following code in Firefox it runs correctly, but in IE8 it says xpath cannot be evaluated or does not result in a WebElement.

webDriver.findElement(By.xpath("//input[@id='submitForm']")).sendKeys("\n");

OR

webDriver.findElement(By.xpath("//input[@id='submitForm']")).click();

I have tried alternate xpath "//div[@id='parameters']/table/tbody/tr[4]/th/input" but it gives same result.

It seems to me that it is a IE driver problem, please let me know if there is a work around.

2条回答
家丑人穷心不美
2楼-- · 2019-02-13 22:27

IE 8 need this top 3 line compulsory in selenium web driver

   DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer(); 
   ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);

   WebDriver webDriver= new InternetExplorerDriver(ieCapabilities);

Please change Xpath by Id:

 webDriver.findElement(By.id("submitForm")).click();
查看更多
男人必须洒脱
3楼-- · 2019-02-13 22:30

Could you try as below?

webDriver.findElement(By.xpath("//input[string(@id)='submitForm']")).click()

For IE doesn't have native XPath support, WebDriver use a third-party library called javascript-xpath for this, this may be a bug of it.

查看更多
登录 后发表回答