我正在使用 Selenium Webdriver(Java),我想使用 IE 驱动程序进行测试,但是我遇到了问题,任何人都可以帮我解决这个问题,在 Firefox 中运行良好的脚本无法运行在 IE 中,我只是打开一个谷歌页面并搜索一些单词,但我的代码只打开谷歌页面写入关键字,但无法使用 IEdriver 点击谷歌页面上的搜索按钮,经过太多谷歌后,我发现了一个当 IE 浏览器时出现的问题get 打开它将在 IE8 兼容性 View 中打开,因此与 FF 相比,它的 id、名称等属性会发生变化,但是当我手动将其更改为 IE8 View 时,属性与 FF 相同,(在键盘打开开发人员上按 F12 键IE 上的工具)所以任何人都可以让我知道如何克服这个问题或如何以 IE8 模式打开 IE 浏览器,或者任何人都知道使用 IE 进行 selenium webdriver 的任何不同解决方案。 我的代码如下
package backOffice;
import java.io.File;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName;
import bsh.ParseException;
public class Time
{
private WebDriver driver;
private String baseUrl= "http://www.google.co.in/";
public static void main(String args[]) throws InterruptedException
{
Time tm=new Time();
tm.trial();
}
private void trial() throws InterruptedException
{
File file = new File("C:/Documents and Settings/Administrator/Desktop/32- bit_IEDriverServer_Win32_2.31.0/IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
DesiredCapabilities caps = DesiredCapabilities.internetExplorer(); caps.setCapability("ignoreZoomSetting", true);
driver=new InternetExplorerDriver(caps);
driver.get(baseUrl + "/");
driver.findElement(By.id("gbqfq")).clear();
driver.findElement(By.id("gbqfq")).sendKeys("harshal kakade");
driver.findElement(By.id("gbqfb")).click();
driver.findElement(By.linkText("Harshal Kakade - India | LinkedIn")).click ();
}
}
谢谢
哈沙尔。
最佳答案
尝试查看互联网选项 -> 安全并取消选中“启用保护模式”。可能是有问题。
关于java - 在 FF 中运行正常的脚本在 IE 中运行失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15763833/