Equivalent code for FireFox and IE browser

226 views
Skip to first unread message

Adi

unread,
Aug 21, 2014, 1:21:59 PM8/21/14
to seleniu...@googlegroups.com
Hi,

For chrome browser, I have following code in my script.

 System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, "chromedriver.exe");
 ChromeDriverService service = ChromeDriverService.createDefaultService();
 ChromeOptions options = new ChromeOptions();
  options.addArguments("allow-running-insecure-content");
 WebDriver driver = new ChromeDriver(service, options);

Same test case I need to execute in FireFox and IE. But I am not able to write proper equivalent code for FireFox and IE browser.
Any idea how to write this in IE and FireFox?

Thanks in adavance,
Adi



Peter Gale

unread,
Aug 21, 2014, 1:38:18 PM8/21/14
to seleniu...@googlegroups.com
You won't need to set a "allow-running-insecure-content" for  Firefox& IE.

While in general your code for one browser will run the same across all browsers, sometimes there are issues where different approaches have to be worked for particular browsers, particularly at startup times.

Your issue was specific to Chrome, though you might encounter other issues particular to IE & FIrefox etc


Date: Thu, 21 Aug 2014 10:21:59 -0700
From: apd...@gmail.com
To: seleniu...@googlegroups.com
Subject: [selenium-users] Equivalent code for FireFox and IE browser
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/f01108f9-790d-4c39-92b5-7e71c8efa8b7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Priya P

unread,
Aug 21, 2014, 7:00:27 PM8/21/14
to seleniu...@googlegroups.com
Create a method to call the type of browser Firefox or chrome or IE

Following is a method to send the type of browser

public class Keyword {
    static WebDriver myDriver;

public static void openBrowser(String vType){
     
        myDriver = new FirefoxDriver();
        myDriver = new InternetExplorerDriver();
        myDriver =new ChromeDriver(); 
       
    }

Priya P

unread,
Aug 21, 2014, 7:27:29 PM8/21/14
to seleniu...@googlegroups.com
And yes, as advised, the same code would work for any browsers. It's all the drivers that needs to be set up.. so you can call a driver type and run for the same code.

Ripon Al Wasim

unread,
Aug 22, 2014, 12:30:07 AM8/22/14
to seleniu...@googlegroups.com
For FF is very simple:

WebDriver driver = new FirefoxDriver();

For IE:

System.setProperty("webdriver.ie.driver","D:/Selenium WebDriver/Driver/IEDriverServer_x64_2.39.0/IEDriverServer.exe"); 
driver = new InternetExplorerDriver();

Please feel free to ask any query/confusion.

br,
ripon


Adi

unread,
Aug 22, 2014, 6:35:03 AM8/22/14
to seleniu...@googlegroups.com
Unfortunately it did not work in both IE and fire-fox :)
It did not work in fire-fox in IE because both are blocking "insecure-content" to execute.
Here is complete code which works in Chrome. Can someone help me write a code which works for all three browsers (IE, Firefox and Chrome)?

import org.junit.Assert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.Test;

public class TestDoubleClick {

@Test
public void testDoubleClick() throws Exception
{
 System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, "chromedriver.exe");
 ChromeDriverService service = ChromeDriverService.createDefaultService();
 ChromeOptions options = new ChromeOptions();
 
  
 options.addArguments("test-type");
 options.addArguments("allow-running-insecure-content");
 WebDriver driver = new ChromeDriver(service, options);



WebElement message = driver.findElement(By.id("message"));
//Verify color is Blue

Assert.assertEquals("rgba(0, 0, 255, 1)", message.getCssValue("background-color").toString());
Actions builder = new Actions(driver);
builder.doubleClick(message).build().perform();
//Verify Color is Yellow
Assert.assertEquals("rgba(255, 255, 0, 1)", message.getCssValue("background-color").toString());
//driver.close();
}
}



Thanks in advance,
Adi

Adi

unread,
Aug 23, 2014, 2:49:57 AM8/23/14
to seleniu...@googlegroups.com
Hello  Peter/Priya/Ripon,

Can you please help me in writing below code for IE and Firefox? It works for Chrome. And for IE and firefox its not working because of unsecured content in the webpage which don't get executed without changing the browsers properties/options. I could change browser properties for chrome but I don't know how to do it for IE and firefox.
Please help. Thanks in advance.

Here is the complete code.

public class TestDoubleClick {
@Test
public void testDoubleClick() throws Exception {
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, "chromedriver.exe");
ChromeDriverService service = ChromeDriverService.createDefaultService();
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
options.addArguments("allow-running-insecure-content");
WebDriver driver = new ChromeDriver(service, options);
WebElement message = driver.findElement(By.id("message"));
//Verify color is Blue
Assert.assertEquals("rgba(0, 0, 255, 1)", message.getCssValue("background-color").toString());
Actions builder = new Actions(driver);
builder.doubleClick(message).build().perform();
//Verify Color is Yellow
Assert.assertEquals("rgba(255, 255, 0, 1)", message.getCssValue("background-color").toString());
//driver.close();
}
}


-Adi

Peter Gale

unread,
Aug 23, 2014, 4:10:44 AM8/23/14
to seleniu...@googlegroups.com

Show use the code you have tried for IE and Firefox, screenshots of the page and any error message(s) and stacktraces.

Adi

unread,
Aug 23, 2014, 2:34:36 PM8/23/14
to seleniu...@googlegroups.com
I used following code for firefox. Error message is attached.

public class DoubleClickFF {

@Test
public void testDoubleClick() throws Exception {
WebDriver driver = new FirefoxDriver();
WebElement message = driver.findElement(By.id("message"));
// Verify color is Blue
Assert.assertEquals("rgba(0, 0, 255, 1)",
message.getCssValue("background-color").toString());
Actions builder = new Actions(driver);
builder.doubleClick(message).build().perform();
// Verify Color is Yellow
Assert.assertEquals("rgba(255, 255, 0, 1)",
message.getCssValue("background-color").toString());
// driver.close();
}
}

-Adi
To post to this group, send email to seleni...@googlegroups.com.
FireFoxErrorMessage.jpg

Peter Gale

unread,
Aug 23, 2014, 3:44:36 PM8/23/14
to seleniu...@googlegroups.com
Adi,

Why are you trying to open a HTML file through drop box?

Why not just download the HTML file and open it directly from your own PC if it is a sample file someone else has provided for you?

On Aug 23, 2014 7:34 PM, Adi <apd...@gmail.com> wrote:
>
> I used following code for firefox. Error message is attached.
>

> public class DoubleClickFF {o

> To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/4618fdad-8e37-43f2-a4b5-961ef569e2b6%40googlegroups.com.

Adi

unread,
Aug 24, 2014, 4:00:59 AM8/24/14
to seleniu...@googlegroups.com
I am not opening any html file and there is no dropbox... error message attached is showing you the warning message given by browser (by manually clicking on warning icon on left side of address bar). firefox browser opened by selenium is blocking the unsecured content in webpage... so double click functionality not working and hence test script is failing..... so if selenium can open webpage without blocking content then selenium script will work... but i dont know how to that...

I think if you execute below code then you will be able to understand the problem better.


public class DoubleClickFF {

@Test
public void testDoubleClick() throws Exception {
WebDriver driver = new FirefoxDriver();
WebElement message = driver.findElement(By.id("message"));
// Verify color is Blue
System.out.println(message.getCssValue("background-color").toString());
Assert.assertEquals("rgba(0, 0, 255, 1)",
message.getCssValue("background-color").toString());
Actions builder = new Actions(driver);
builder.doubleClick(message).build().perform();
// Verify Color is Yellow
Assert.assertEquals("rgba(255, 255, 0, 1)",
message.getCssValue("background-color").toString());
// driver.close();
}
}


Thanks in advance,
-Adi

Peter Gale

unread,
Aug 24, 2014, 6:26:50 AM8/24/14
to seleniu...@googlegroups.com

Adi ....  your code does have the line "go to URL at Dropbox ...". That. Is clearly where your browser is pointing to.

Adi

unread,
Aug 25, 2014, 1:25:17 PM8/25/14
to seleniu...@googlegroups.com
Thanks for replying Peter...

-Adi

Reply all
Reply to author
Forward
0 new messages