简体   繁体   中英

Selenium Code Not Working for Internet Explorer

I am trying to perform automation testing using Selenium with Java in Eclipse IDE.

My automation testing source code is given as follows:

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"));            
    }
}

I have a Windows 8 system and have downloaded the proper Selenium Web driver for Internet Explorer, Firefox and Chrome.

The problem here is that despite setting the environment variable and starting the Selenium RC server from Command Prompt by executing the jar file, the website (Google) is not opened. Instead of directing me to http://www.google.com , the RC server directs me to C:\\Users\\rugved.mandrekar\\AppData\\Local\\Temp\\customProfileDir1b3a3fa718214e7cae8240f4cf54293e\\core\\Blank.html as highlighted in the following screenshot:

网址错误

I had created the above code a day ago and it was getting executed perfectly. Currently too, the test is performed in other browsers such as Chrome and Firefox. In other words when I change *iexplore in line 10 in the SearchTest.java file to firefox or chrome, the test gets executed. Also there is an error message in the Selenium console log which has started popping up from today. The screenshot of the error message is as follows:

Selenium日志窗口中的错误消息

Can anyone tell me where exactly am I going wrong? Replies at the earliest will be highly appreciated. Thank you in advance.

In Internet Expolorer:

  • Click on “Sites” button and add the Urls of the application you are testing in Add this website to the zone: and clicking on Add button.

  • Disable popup block. - Select Tools/Popup Blocker/Turn off pop-up blocker

  • Disable IE protected mode. - Untick Tools/Internet Options/Security/Enable protected mode

  • Ensure you run Internet Explorer and your IDE as Administrator .

In the Code

  • Try changing the browser string to

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

Credit to this answer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM