【问题标题】:Script running fine in FF fails to run in IE在 FF 中运行良好的脚本无法在 IE 中运行
【发布时间】:2013-04-02 12:12:55
【问题描述】:

我正在使用 Selenium Webdriver(Java),我想使用 IE 驱动程序进行测试,但是我遇到了问题,谁能帮我解决这个问题,在 firefox 中运行良好的脚本无法运行在 IE 中,我只是打开一个谷歌页面并搜索一些单词,但我的代码只打开谷歌页面写关键字但无法使用 IEdriver 在谷歌页面上点击搜索按钮,在谷歌太多之后我发现了一个当 IE 浏览器获取打开它将在 IE8 兼容性视图中打开,因此它的 id、名称等属性与 FF 相比会发生变化,但是当我手动将其更改为 IE8 视图时,属性与 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 ();      
  }  
 }

谢谢,

哈沙尔。

【问题讨论】:

  • 也许这会有所帮助:stackoverflow.com/questions/5804714/…
  • 你真的应该试试这个不是谷歌的东西。 Google 的标记非常复杂,例如,我在您使用的元素上得到完全不同的 ID。
  • 嗨,Arran,我尝试使用其他网络也同样是我观察到的行为。谢谢,哈沙尔。
  • 任何人都可以帮我解决这个问题......请

标签: java selenium


【解决方案1】:

尝试查看互联网选项 -> 安全性并取消选中“启用保护模式”。应该是有问题吧。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多