I am working on writing an automation script to test a website login. Through Firefox IDE, I have written TestCase steps, it is executing fine. I exported the test case as java code compatible with jUnit 4.
When i try to run the java code via Eclipse (with firefox browser), either it opens Mozilla homepage or blank page or proxy issue (if my machine is connected to company LAN).
I am using Selenium 2.44 and Firefox version 44..
Also i read in some websites saying about compatible version of firefox with selenium web driver. I am confused a lot regarding this.
Please let me know which version of Selenium Web driver, Firefox & Java is preferred..!!!
Adding my java code below
public class Firefox {
private WebDriver driver;
private String PROXY = "proxy address:port";
private String baseUrl;
private boolean acceptNextAlert = true;
#Before
public void setUp() throws Exception {
// Code for setting up Firefox proxy
Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setHttpProxy(PROXY)
.setFtpProxy(PROXY)
.setSslProxy(PROXY);
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(CapabilityType.PROXY, proxy);
driver = new FirefoxDriver(cap);
baseUrl = "url";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Test
public void testFirefox() throws Exception {
driver.get(baseUrl);
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try {
if ("".equals(driver.findElement(By.id("userId")).getText())) break;
}
catch (Exception e) {}
Thread.sleep(1000);
}
driver.findElement(By.id("userId")).sendKeys("user name");
driver.findElement(By.id("pwd")).sendKeys("password");
driver.findElement(By.id("sign-in")).click();
}
}
Latest stable compatible configuration which i've found and I am using it is selenium Webdriver 2.48.2 and Firefox 41.0.2
Download Firefox ESR from https://www.mozilla.org/en-US/firefox/organizations/all/
Its stable version browser of Firefox compatible with Webdriver 2.48.2.
Selenium WebDriver 2.48.2 will not work with FF 44.
The latest Firefox always works with the latest version of Selenium (2.x versions) for all non-native events, such as JavascriptExecutor events, but there are some native events (such as driver.navigate.to() and driver.click() that won't work except with the last known native supported version of Firefox, which was 31.6.0 ESR. It's possible that later versions of ESR will work, but I have not read that anywhere.
Related
Everything is working completely fine except this one proxy login which I can’t bypass.
Here is what I've tried to pass this:
https://{USERNAME}:{PASSWORD}#url - This still displays the same popup
driver.switchTo().alert().sendKeys(proxy.getUsername()); // Alert is never found.
driver.switchTo().activeElement().sendKeys(proxy.getUsername()); // Nothing happens
new Actions(driver).sendKeys(proxy.getUsername()).build().perform(); // Nothing is happening
Here is the code I'm using to connect to the url
public void execute(ProxyConnection proxy) {
WebDriver driver = setupDriver(proxy);
driver.get(URL);
driver.manage().window().maximize();
// Here I use test methods like shown above
}
public WebDriver setupDriver(ProxyConnection proxyConnection) {
System.setProperty("webdriver.chrome.driver", "MY PATH");
String proxyadd = proxyConnection.getHostName() + ":" + proxyConnection.getPort();
Proxy proxy = new Proxy();
proxy.setHttpProxy(proxyadd);
proxy.setSslProxy(proxyadd);
ChromeOptions options = new ChromeOptions();
options.setCapability("proxy", proxy);
if (!debugMode) {
options.addArguments("--headless");
}
return new ChromeDriver(options);
}
I'm using ChromeDriver version: 91.0.4472
I'm using selenium-chrome-driver version: 3.8.0
Any help is greatly appreciated.
Still no answer to this.
I even tried playing around with selenium and chrome versions but still no luck. I updated to BETA v4.0.0 and this didn't have any effect.
AutoIT or Robot is not suitable because it needs to be headless.
Try to use
driver.switchTo().alert().sendKeys("username");
You find more exemples in https://www.guru99.com/alert-popup-handling-selenium.html
For anyone wondering what the solution was because I was testing for hours and hours but finally found one that works...
((HasAuthentication) driver).register(UsernameAndPassword.of(ProxyData.getInstance().getUsername(), ProxyData.getInstance().getPassword()));
Note: This requires version Selenium 4.0.0 or higher.
I am passing mvn command with -Dbrowser=firefox never launches firefox. Below is my code to initialize browser and it works for Chrome but does not launch Firefox nor Edge. I have added webdrivermanager latest maven dependency 4.2.2 to my pom.xml. I have Firefox 81.0 and Edge 85.0 versions, respectively.
public WebDriver Init_Browser(String browser) {
strBrowser = prop.getProperty("browser");
if (strBrowser.equalsIgnoreCase("chrome")) {
System.setProperty(ChromeDriverService.CHROME_DRIVER_SILENT_OUTPUT_PROPERTY, "true"); // This statement will
// remove rendering
// statements while
// page loading
WebDriverManager.chromedriver().setup();
tldriver.set(new ChromeDriver());
} else if (strBrowser.equalsIgnoreCase("ff") || (strBrowser.equalsIgnoreCase("firefox"))) {
WebDriverManager.firefoxdriver().setup();
tldriver.set(new FirefoxDriver());
} else if (strBrowser.equalsIgnoreCase("Edge")) {
WebDriverManager.edgedriver().setup();
tldriver.set(new EdgeDriver());
} else {
System.out.println("Browser not defined");
}
getDriver().manage().deleteAllCookies();
getDriver().manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);
return getDriver();
}
Please help in fixing this issue. Thank you.
I was loading default browser value from properties file.
strBrowser = prop.getProperty("browser");
Instead I replaced this statement to,
String strBrowser = System.getProperties().get(browser).toString();
So the browser value coming from parameters sits in get(browser) and it will validate according to the browser requirement. Problem solved. I was able to launch firefox, edge and chrome without any issues.
I am using Selenium in a Burp plugin but I can't load pages with the get method. Browsers open correctly, both Firefox and Chrome, but they don't load the page. Chrome address bar shows "data;.", while Firefox has no text in it. I am using the last driver available, Chrome 81.0.4044.183 and the driver for this exact version, while Firefox is 76.0.1 and I am using GeckoDriver 0.24 (since 0.25+ have a known bug) and it works with the last version of Firefox.
The code is the following
void runBrowserAutomatization(File fileDriver, String seleniumTrack, boolean isHeadless) {
WebDriver driver;
if (gui.usedBrowser().toLowerCase().contains("chrome")) {
ChromeOptions options = new ChromeOptions();
Proxy proxy = new Proxy();
proxy.setHttpProxy("localhost:8080");
proxy.setSslProxy("localhost:8080");
options.setCapability(CapabilityType.PROXY, proxy);
options.setHeadless(isHeadless);
System.setProperty("webdriver.chrome.driver", fileDriver.getPath());
driver = new ChromeDriver(options);
} else if (gui.usedBrowser().toLowerCase().contains("firefox")) {
FirefoxOptions options = new FirefoxOptions();
Proxy proxy = new Proxy();
proxy.setHttpProxy("localhost:8080");
proxy.setSslProxy("localhost:8080");
options.setCapability(CapabilityType.PROXY, proxy);
options.setHeadless(isHeadless);
System.setProperty("webdriver.gecko.driver", fileDriver.getPath());
driver = new FirefoxDriver(options);
} else {
PrintMsg("No browser selected...");
return;
}
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://www.nytimes.com/");
driver.quit();
}
I may also think it is a Proxy misconfiguration, Burp certificate is installed in Firefox and Windows (where Chrome gets Certificate Authorities) but is not shown in the settings of the instance started by Selenium. Any help or suggestion is highly appreciated, thnaks.
My Firefox version is 46.0.1 and Selenium version is 3.0.1.
I am getting error:
Your connection is not secure
while executing following code:
#Test
public void test() {
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffProfile = profile.getProfile("newCretedProfile");
ffProfile.setAcceptUntrustedCertificates(true);
ffProfile.setAssumeUntrustedCertificateIssuer(false);
System.setProperty("webdriver.gecko.driver", "D:\\SELENUIUM\\Drivers\\geckodriver.exe");
FirefoxDriver driver = new FirefoxDriver(ffProfile);
driver.get("http://www.google.com");
driver.quit();
}
I have created new firefox profile and followed steps from this url
Nevertheless it's not working and giving me same error while I launching any site.
Download Firefox 55 beta and set
capabilities.setCapability("acceptInsecureCerts", true);
Here is my code that works for Firefox 55 beta:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName("firefox");
capabilities.setCapability("acceptInsecureCerts", true);
RemoteWebDriver driver = new RemoteWebDriver(Environment.remoteWebDriverURL, capabilities);
I have tried this approach and it worked well for me.
Create new firefox profile by following below step.
Close all your firefox windows
In the Run dialog box, type in: ‘firefox.exe -p' and then Click OK.
Click “Create Profile”
Create a name for your new profile(say Selenium)
Click “Choose Folder”
Pick location something easy to find — like “C:\NewFirefoxProfile”
Click Finish
Now after selecting newly created profile, start Firefox. Open the specific url you were getting 'Secure Connection Issue', accept SSL certificates for this profile.
Now use the newly created firefox profile to run your selenium test. Modify below code as per your requirement.
System.setProperty("webdriver.firefox.marionette","D:\\SELENUIUM\\Drivers\\geckodriver.exe");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("C:\\NewFirefoxProfile");//location of your new firefox profile
WebDriver driver = new FirefoxDriver(myprofile);
driver.get("https://cacert.org/");
With FF v53+ and Se 3.x (summer 2017), advice from before (May?) 2017 is no longer true.
You have to use Marionette and set capability to True.
Took me few days to sort out all old and obsolete advice, yours for free. :-)
Looks like it is not supported yet by geckodriver/Marionette.
You can check below bugs for more information:-
https://github.com/mozilla/geckodriver/issues/93
https://bugzilla.mozilla.org/show_bug.cgi?id=1103196
If you want to run the tests on Firefox with Selenium 3.0 set the Firefox driver capability “marionette” to false.
#Test
public void test() {
DesiredCapabilities d = new DesiredCapabilities();
d.setCapability("marionette", false);
WebDriver driver = new FirefoxDriver(d);
driver.get("http://www.google.com");
driver.quit();
}
I am trying to run some automated tests on IE11 using Selenium Webdriver. Whenever I run my code the URL that IE tries to load is http://--port=38198/
I am trying to simply load Google and return the title, then I will move onto the actual automated testing I intend to do.
Here is a sample of my code so far;
private WebDriver driver;
private String baseUrl;
#Before
public void setUp() throws Exception{
System.setProperty("webdriver.ie.driver", "C:\\Program Files\\Internet Explorer\\iexplore.exe");
DesiredCapabilities cap = DesiredCapabilities.internetExplorer();
cap.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
baseUrl = "http//www.google.com";
driver = new InternetExplorerDriver(cap);
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Test
public void test() throws Exception{
driver.get(baseUrl);
System.out.println(driver.getTitle());
//driver.navigate().to(baseUrl);
}
Ever time I run my code it always opens the same URL - http://--port=
From my code I can't see where I have gone wrong. I changed the security settings on IE to medium and disabled protected mode (I have tried it with protected mode turned on and still no luck). I have also downloaded and installed Microsofts IE11 web driver.
I am totally mystified by this, can someone give me any insight into this...
It seems that you are using your native Windows IE?
You have to download the IE WebDriver from https://code.google.com/p/selenium/wiki/InternetExplorerDriver and your webdriver.ie.driver property needs the path to the downloaded IEDriverServer.exe
Please try and report if that solves your problem. If not I will change my chrome WebDriver to the IE and try it myself :)