Selenium Proxy Pop up in Java - java

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.

Related

Selenium can't open Gitlab login page

I'm doing an automated test, using Java (8), Selenium (4) and Chromedriver (98.0).
The test is for a site that requires to login with different third party accounts, one of them being GitLab.Unfortunately the test always gets stuck while trying to access Gitlab's login page, on the "Checking your browser before accessing gitlab.com" part. If I pause the test on this step and duplicate the tab manually, the newly opened tab will be able to enter and then the first one will be also able to do it (probably because at that point finally has a valid cookie).I've tried out different solutions but with no luck. Currently this is my code:
#Test
public void test() throws MalformedURLException {
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-dev-shm-usage");
options.addArguments("--disable-blink-features=AutomationControlled");
options.addArguments("--start-maximized");
options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
options.setExperimentalOption("useAutomationExtension", false);
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), options);
driver.navigate().to("https://gitlab.com/users/sign_in");
new FluentWait<>(driver)
.withTimeout(Duration.ofSeconds(60))
.pollingEvery(Duration.ofSeconds(2))
.until(x -> driver.findElements(By.xpath("//*[#data-translate='checking_browser']")).size() == 0);
}
When trying to use undetected_chromedriver, using Python, it worked, but it's a requirement for me to use Java. Is there something similar for Java or is there an extra ChromeOption that I'm missing?
need to download chrome driver https://chromedriver.chromium.org/downloadshttps://chromedriver.chromium.org/downloads
and add this code while setting up driver
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
WebDriver driver = new ChromeDriver();

Firefox Error: "Your connection is not secure" while launching driver with Selenium 3.0.1 using Java

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

Selenium WebDriver + Firefox which version works fine?

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.

Selenium Webdrivers: Load Page without any resources

I am trying to prevent Javascript from changing the site's source code I'm testing with Selenium. The problem is, I can't just simply turn Javascript off in the Webdriver, because I need it for a test. Here's what I'm doing for the Firefox Webdriver:
firefoxProfile.setPreference("permissions.default.image", 2);
firefoxProfile.setPreference("permissions.default.script", 2);
firefoxProfile.setPreference("permissions.default.stylesheet", 2);
firefoxProfile.setPreference("permissions.default.subdocument", 2);
I don't allow Firefox to load any Images, Scripts and Stylesheets.
How can I do this with the Internet Explorer Webdriver and the Chrome Webdriver? I have not found any similar preferences. Or is there even a more elegant way to stop the webdrivers from loading the site's JS Files after all?
Thank you!
Solution is to use proxy. Webdriver integrates very well with browsermob proxy: http://bmp.lightbody.net/
private WebDriver initializeDriver() throws Exception {
// Start the server and get the selenium proxy object
ProxyServer server = new ProxyServer(proxy_port); // package net.lightbody.bmp.proxy
server.start();
server.setCaptureHeaders(true);
// Blacklist google analytics
server.blacklistRequests("https?://.*\\.google-analytics\\.com/.*", 410);
// Or whitelist what you need
server.whitelistRequests("https?://*.*.yoursite.com/.*. https://*.*.someOtherYourSite.*".split(","), 200);
Proxy proxy = server.seleniumProxy(); // Proxy is package org.openqa.selenium.Proxy
// configure it as a desired capability
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, proxy);
// start the driver ;
Webdriver driver = new FirefoxDriver(capabilities);
//WebDriver driver = new InternetExplorerDriver();
return driver;
}
Probably the easiest way to accomplish what you want in a cross-browser way is to use a proxy. This would allow you to intercept requests for resources, and block them. This would also have the advantage of using the same code for all browsers, rather than having to special-case each browser with settings unique to that browser.

how to over come ssl certifcate error for selenium web driver in Internet Explorer

I am new to Selenium Web driver and using this with Java.
I am able to launch an application but I am getting the SSL certificate error, could anyone please let me know how to overcome this issue.
I am actually learning it and need to implement at my work, if I could overcome this will be very helpful.
I am using the following code :
public class Test1 {
private static InternetExplorerDriver driver;
#Before
public void beforeclass ()
{
System.setProperty("webdriver.ie.driver", "C:\\My Folder\\selenium-2.33.0\\IEDriverServer.exe");
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setJavascriptEnabled(true);
driver = new InternetExplorerDriver(capabilities);
}
#Test
public void Test() throws Exception
{
driver.get("www.gmail.com");
driver.getTitle();
driver.getCurrentUrl();
System.out.println(driver.getCurrentUrl());
driver.findElement(By.name("username")).sendKeys("Admin1");
driver.findElement(By.name("password")).sendKeys("Password2");
}
#After
public void afterclass()
{
System.out.println("webdriver");
}
}
Thanks in advance.
I dont' think there is a way to properly set it. CapabilityType.ACCEPT_SSL_CERTS won't work for IE I suppose, Selenium is designed to ignore the invalid capability for the particular browser and won't throw an exception.
Here is a workaround you can click link "Continue to this website (not recommended)." to bypass it.
Try
// check if your driver is IEDriver and driver's Title contains "Certificate"
// then
driver.navigate().to("javascript:document.getElementById('overridelink').click()");
driver.findElement(By.name("username")).sendKeys("Admin1");
driver.findElement(By.name("password")).sendKeys("Password2");
Facing the same issue i solved it adding target ssl certificates to IE trusted certificates on machine where test executes.
This solved in local dev machine and also on grid execution.(Certificates imported there)
This precentes certificate revogation warning to display on IE.
I did solve this issue by making changes in the settings.Try
Tools-> Internet options->Advanced-> Settings->under security uncheck " Warn if changing between secure and not secure mode"
and Restart your IE.

Categories

Resources