【问题标题】:Unable to click the link on IE using IEDriver无法使用 IEDriver 在 IE 上单击链接
【发布时间】:2015-08-20 01:15:56
【问题描述】:

我使用的代码如下所示。

多浏览器

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

   <?xml version="1.0" encoding="UTF-8"?>    
   <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">    
   <suite name="Suite" parallel="none">    
    <test name="FirefoxTest">    
     <parameter name="browser" value="firefox" />    
     <classes>    
      <class name="com.MultiBrowser" />    
     </classes>    
    </test>    
    <test name="IETest">     
     <parameter name="browser" value="ie" />    
     <classes>    
      <class name="com.MultiBrowser" />    
     </classes>     
    </test> 
   </suite>    

当我使用 Firefox 时它运行良好,但是当我在 IE 上运行相同的代码时出现以下问题

例外:

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

【问题讨论】:

标签: java internet-explorer firefox selenium selenium-webdriver


【解决方案1】:

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

1.打开IE

2.进入工具 -> Internet 选项 -> 安全

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

【讨论】:

    猜你喜欢
    • 2015-09-14
    • 2017-10-20
    • 2017-08-31
    • 1970-01-01
    • 2018-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多