我正在使用的代码如下所示。
多浏览器
<span class="favorBOfont">Country Selection</span><p> </p>
<form name="tripleplay" action="">
Category:
<select name='List1' onchange="fillSelect(this.value,this.form['List2'])">
<option selected>Make a selection</option>
</select>
<p> </p>
<p>
Content:
<select name='List2' onchange="getValue(this.value, this.form['List1'].value)">
<option selected>Make a selection</option>
</select>
<!-- onchange="fillSelect(this.value,this.form['List3'])" -->
</p>
</form>
<p> </p>
<p>
<textarea rows="8" cols="88" id="lname" name="lname" size="30" height="30" readonly></textarea>
</p>
<div></div>
TestNG.xml
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();
}
}
当我使用Firefox时它工作正常,但当我在IE上运行相同的代码时,我得到以下问题
例外:
无法找到xpath == .//* [/ id =&#39; account&#39;] / a的元素(警告:服务器未提供任何堆栈跟踪信息)
答案 0 :(得分:0)
需要在所有区域中设置安全级别。为此,请按照以下步骤操作:
1.打开IE
2.转到工具 - &gt;互联网选项 - &gt;安全
3.应启用安全性中的所有复选框。