【问题标题】:Selenium Code Not Working for Internet ExplorerSelenium 代码不适用于 Internet Explorer
【发布时间】:2014-08-24 10:30:47
【问题描述】:

我正在尝试在 Eclipse IDE 中使用 Selenium 和 Java 执行自动化测试。

我的自动化测试源码如下:

TestClass.java

package testproject;

import login.*;

public class TestClass {

    public static void main(String[] args) {
        SearchTest st = new LoginTest();
        try {
            st.setUp();
            st.testNew();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

SearchTest.java

package login;

import com.thoughtworks.selenium.*;

import java.util.regex.Pattern;

public class SearchTest extends SeleneseTestBase {
    
    public void setUp() throws Exception {
        setUp("http://www.google.com/", "*iexplore");
    }
    
    public void testNew() throws Exception {
        selenium.open("/");
        selenium.type("q", "selenium rc");
        selenium.click("btnG");
        selenium.waitForPageToLoad("30000");
        assertTrue(selenium.isTextPresent("Results * for selenium rc"));            
    }
}

我有一个 Windows 8 系统,并且已经为 Internet Explorer、Firefox 和 Chrome 下载了适当的 Selenium Web 驱动程序。

这里的问题是,尽管设置了环境变量并通过执行 jar 文件从命令提示符启动 Selenium RC 服务器,但网站 (Google) 没有打开。 RC 服务器没有将我定向到 http://www.google.com,而是将我定向到 C:\Users\rugved.mandrekar\AppData\Local\Temp\customProfileDir1b3a3fa718214e7cae8240f4cf54293e\core\Blank.html,如下图所示:

我在一天前创建了上面的代码,它正在完美地执行。目前,该测试也在其他浏览器中进行,例如 Chrome 和 Firefox。换句话说,当我将 SearchTest.java 文件第 10 行中的 *iexplore 更改为 firefox 或 chrome 时,测试将被执行。 Selenium 控制台日志中还有一条错误消息,从今天开始弹出。报错信息截图如下:

谁能告诉我我到底哪里出错了?尽早回复将不胜感激。提前谢谢你。

【问题讨论】:

  • 您是否启用了弹出窗口拦截器?
  • 非常感谢您的回复。不,我没有启用弹出窗口阻止程序。
  • 酷,可能是非常愚蠢的问题,但最好先做基本的东西! IE很繁琐,你是以管理员身份运行的吗?我现在会看代码等,但最好先尝试环境方面的东西。也可以在 IE 中尝试:单击“站点”按钮并在“将此网站添加到区域:”中添加您正在测试的应用程序的 URL,然后单击“添加”按钮。 any of this work?
  • 抱歉重复评论,试试这个Internet Options > Security > uncheck the Enable Protected mode checkbox and try running the script. 也以管理员身份运行所有内容,这意味着您的 IDE 和浏览器。
  • 好的,成功了。非常感谢您的帮助;非常感激。干杯。 :-)

标签: java eclipse internet-explorer firefox selenium


【解决方案1】:

在 Internet Explorer 中:

  • 单击“站点”按钮并添加您所在应用程序的 URL 在Add this website to the zone: 中测试并点击Add 按钮。

  • 禁用弹出块。 - 选择Tools/Popup Blocker/Turn off pop-up blocker

  • 禁用 IE 保护模式。 - 取消勾选Tools/Internet Options/Security/Enable protected mode

  • 确保以管理员身份运行 Internet Explorer 和 IDE。

在代码中

  • 尝试将浏览器字符串更改为

ISelenium selenium = new DefaultSelenium("localhost", 4444, "*iexploreproxy", "http://www.google.com/");

Credit to this answer

【讨论】:

  • 您回答的第二部分帮助我解决了问题,因为我已经关闭了弹出窗口阻止程序。谢谢你。 :-)
  • 我很高兴 :) 很高兴它有帮助。几周后我将在新工作中使用 Selenium,我可能会有大约一百万个问题!
猜你喜欢
  • 2013-07-05
  • 2014-02-28
  • 2015-12-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-25
  • 1970-01-01
相关资源
最近更新 更多