无法使用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.应启用安全性中的所有复选框。
- 用于保存文件的Selenium firefox配置文件
- Selenium在一台计算机上发生了“UnreachableBrowserException / Address has in use”
- geb.driver.DriverCreationException:无法从回调创建驱动程序
- 使用Selenium在FireFox中设置首选项时出现mime类型问题
- Selenium 3.0 Firefx驱动程序因org.openqa.selenium.SessionNotCreatedException而失败:无法创建新的远程会话
- 使用selenium的java出错:预期
- 使用selenium Java(Mac OSX)将Firefox浏览器置于前端
- “安全设置阻止的应用程序”阻止在Linux上使用oracle SE 7更新51运行的applet
- Selenium WebDriver鼠标操作moveToElement不会在Firefox Linux上引发mouseout事件