java - 在 FF 中运行正常的脚本在 IE 中运行失败

标签 java selenium

我正在使用 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/

相关文章:

java - 构造函数可以在Java中抛出异常吗?

java - 如何用 jmockit 模拟 InitialContext 类?

python - 尝试使用 Selenium 单击按钮时出错

javascript - getText() 在 Selenium 中返回一个空白,即使文本没有被隐藏。我也试过 JavaScript

google-chrome - Chrome 59 挂起 --headless 和 --proxy-server 标志

python - 如何获取网页中的特定框架并检索其内容

java - LUAJ 强制 Java 对象不接受 LuaValue 参数

java - C# MD5 哈希与 Java MD5 不同

java - ComboBox 项目重叠

java - 如何使用selenium点击由6位数字生成名称的按钮?