无法使用IEDriver单击IE上的链接

我正在使用的代码如下所示。

多浏览器

package com; import java.io.File; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.ie.InternetExplorerDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Parameters; import org.testng.annotations.Test; public class MultiBrowser { public WebDriver driver; // Passing Browser parameter from TestNG xml @Parameters("browser") @BeforeClass public void beforeTest(String browser) { // If the browser is Firefox, then do this if(browser.equalsIgnoreCase("firefox")) { driver = new FirefoxDriver(); }else if (browser.equalsIgnoreCase("ie")) { DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); File fil = new File("C:\\IEDriver\\IEDriverServer.exe"); System.setProperty("webdriver.ie.driver", fil.getAbsolutePath()); driver = new InternetExplorerDriver(capabilities); } driver.get("http://www.store.demoqa.com"); } @Test public void login() throws InterruptedException{ driver.findElement(By.xpath(".//*[@id='account']/a")).click(); driver.findElement(By.id("log")).sendKeys("testuser_1"); driver.findElement(By.id("pwd")).sendKeys("Test@123"); driver.findElement(By.id("login")).click(); } @AfterClass public void afterTest(){ driver.quit(); } } 

的testng.xml

                  

当我使用Firefox时它工作正常,但当我在IE上运行相同的代码时,我得到以下问题

例外:

无法使用xpath == .//* [@ id =’account’] / a查找元素(警告:服务器未提供任何堆栈跟踪信息)

它需要在所有区域中设置安全级别。 为此,请按照以下步骤操作:

1.打开IE浏览器

2.转到工具 – > Internet选项 – >安全性

3.应启用安全性中的所有复选框。