My apologies in advance if my question sounds primary, I am very new at QA and Selenium.
I am using Java and Selenium to write a test, at one of my test's step when I click on a button it is supposed to open another window but Chrome blocks the popup window, can I enable popup by Selenium?
Well, you need to initialize the ChromeDriver with a customized configuration which will disable the flag to block popups. From this site, the command line switch for it is disable-popup-blocking. So, using ChromeOptions and DesiredCapabilities, you add the desired config using the DesiredCapabilities.setCapability() function.
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
options.addArguments("disable-popup-blocking");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(capabilities);
EDIT: Just found the same solution on this site.
There is also another option to enable popup windows. Because sometimes your company may block you from accessing any application in admin mode. If the above method fails to work, you can use the below codes to enable pop ups.
WebDriver driver = new ChromeDriver(options);
driver.manage().window().maximize();
driver.get("chrome://settings/content");
Thread.sleep(4000);
driver.switchTo().frame("settings");
Thread.sleep(2000);
driver.findElement(By.xpath("//input[#type='radio' and #name='popups']")).click();
Thread.sleep(4000);
driver.findElement(By.id("content-settings-overlay-confirm"));
Thread.sleep(4000);
Use the above code before starting your test.
If anyone is still encountering this problem, it's probably because they are on an old version of ChromeDriver. Popup blocking was disabled by default from version 21+
Reference: https://bugs.chromium.org/p/chromedriver/issues/detail?id=1291
For me worked this solution:
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-web-security");
ChromeDriver driver = new ChromeDriver(options);
Related
I have tested every method but still can't pass the block some reason. Not even trying to automate anything. Example page URL. I can access main page but can't access any link inside the web site with webdriver.
Java Code:
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-blink-features");
options.addArguments("--disable-blink-features=AutomationControlled");
options.addArguments("--disable-gpu");
options.addArguments("--no-sandbox");
WebDriver driver=new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("https://www.sahibinden.com/ilan/hayvanlar-alemi-aksesuarlar-buyukbas-kucukbas-10x60-hayvan-yasam-alani-600metrekare-706539205/detay");
It worked with firefox driver + useragent + enabling javascript. I think I had some version issues on google driver.
Is it possible to use proxy after starting chromedriver on the same browser?
EX:
I start chrome driver
Load website
Put in info
Use proxy
Click submit
I think i found some ways to do it in python and JS but im not sure how to convert it to java
As per Selenium's current implementation once you configure the WebDriver instance with the required Options and Capabilities and initialize the WebDriver session to open a Web Browser, you cannot change the capabilities runtime. Even if you are able to retrieve the runtime capabilities still you won't be able to change them back.
So, in-order to use a proxy you have to initiate a new WebDriver session.
here is #JimEvans clear and concise comment (as of Oct 24 '13 at 13:02) related to proxy settings capability:
When you set a proxy for any given driver, it is set only at the time WebDriver session is created; it cannot be changed at runtime. Even if you get the capabilities of the created session, you won't be able to change it. So the answer is, no, you must start a new session if you want to use different proxy settings.
You can find a relevant discussion in Set capability on already running selenium webdriver
You can use ChromeOptions class.
You can create an instance of ChromeOptions, which has convenient methods for setting ChromeDriver-specific capabilities. You can then pass the ChromeOptions
object into the ChromeDriver constructor:
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("/path/to/extension.crx"));
ChromeDriver driver = new ChromeDriver(options);
ChromeOptions options = new ChromeOptions();
// Add the WebDriver proxy capability.
Proxy proxy = new Proxy();
proxy.setHttpProxy("myhttpproxy:3337");
options.setCapability("proxy", proxy);
// Add a ChromeDriver-specific capability.
options.addExtensions(new File("/path/to/extension.crx"));
ChromeDriver driver = new ChromeDriver(options);
I have requirement that everytime i login, it asking security code in webapp. But it will ask only once since browser stored the cookies.but it is asking again and again in selenium webdriver since driver always opening new browser every time.
So i need to use already opened browser in selenium webdriver java. please help me with example code.
Finally i found solution that using google chrome option in java. It stores cookies in your temp file and reusing it everytime.
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
options.addArguments("start-maximized");
options.addArguments("user-data-dir=D:/temp/");
capabilities.setCapability("chrome.binary","res/chromedriver.exe");
capabilities.setCapability(ChromeOptions.CAPABILITY,options);
driver1 = new ChromeDriver(capabilities);
Everytime that I start the Chrome web browser, using chromedriver, it starts up clean with any custom settings disabled. I have a case where I am logged in on a website and I want to access the account to get some information. However, the newly opened browser is not logged into the account anymore. Even when I open a new browser manually I am still logged in on that same page. Is there a way to enable custom settings? Preferably in Java.
You can achieve this by using ChromeOptions as below :-
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
String chromeDirPath = "provided here a path where you want to custom chrome dir which could be use everty time you launch"
//ensure chromeDirPath exist in dir
ChromeOptions options = new ChromeOptions();
options.addArguments("--user-data-dir="+chromeDirPath);
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(capabilities);
driver.get("url");
Now it will maintain your custom browser setting at chromeDirPath
Hope it will help you.
I am using Selenium and ChromeDriver 2.43.1 with the latest Chrome (Version 42.0.2311.135 at the time the quetion was asked). My web application generates a PDF. It is being sent with the correct MIME type and it also correctly opens in the Chrome PDF viewer. However when I try to open the PDF using Selenium in Chrome that is started by the WebDriver, it gets downloaded.
I believe it might be some settings that Selenium or WebDriver use to start Chrome.
I've tried settings a few switches, but nothing worked yet. My code:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
// Add ChromeDriver-specific capabilities through ChromeOptions.
ChromeOptions options = new ChromeOptions();
options.addArguments("--please-make-it-work"); // not a real switch
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
webDriver = new ChromeDriver(capabilities);
webDriver.get(url);
What I really need is to start the browser in "normal" mode. It doesn't need any profile settings, just the defaults that will open the PDF.
The problem was caused by the recent change to the behaviour of the --test-type switch. It is described in the ChromeDriver issue tracker.
The workaround is to disable this switch. Here's my code changed:
// Add ChromeDriver-specific capabilities through ChromeOptions.
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("excludeSwitches", Arrays.asList("test-type"));
webDriver = new ChromeDriver(options);
webDriver.get(url);