I am looking for how to open selenium webdriver in a new tab of a firefox already opened. I aim to do that beacause when my java program (webdriver) open firefox, i have to set profile params in my program. To do this, i must every time log on in a dialog frame, because i have installed cntlm.
In short, I want to open firefox in a new tab.
Thaks a lot!
Please watch this Selenium feature ticket for progress.
Issue 18: Allow webdriver to attach to a running browser
Your summary "In short, I want to open firefox in a new tab." is ambiguous and confusing, if you are looking for how to open new tab, see this question.
Related
I'm working with Selenium, Java and Browserstack. Usually I develop in MacOS and I improve the compatibility with the remote browser. I'm trying to execute the same test cases that are working properly in MacOS, into a Windows remote machine.
The problem appears when I let a form incomplete because and I have clicked on a Cancel button to back again to the previous page. In this scenario the default chrome alert appears:
I have tried the Chrome option:
options.addArguments("--disable-notifications");
Also:
options.addArguments("--disable-popup-blocking");
And with:
prefs.put("profile.default_content_settings.popups", 0);
I know I can use a condition in the cancel button associated to the system configuration, where the selenium code accept the alert, but I'm searching an option more cleaning and easy.
Do you know any other option, capability or whatever, that could block those pop-ups but not the others?
Thank you in advance.
EDIT NOTE
It is something related with Chrome pop-ups only.
Please try
prefs.put("profile.default_content_setting_values.notifications", 2);
I am clicking a link via Selenium webdriver and the link opens up a new windows - I want to force the link to open in the same window (and the same tab) is this possible?
Most of the time this does not happen only with a specific link..
Thanks
Before clicking the link update the link's target property to self and then click it.
For updating the property please refer to this link.
See if the HTML code is like below, link will open in a different tab/windows depending upon the browser settings.
<a href = "#" target = "_blank">
When a Firefox browser is launched via Selenium Webdriver, the default profile it launches by default has this option enabled. You can create a new firefox profile by disabling this option. In this case the link will open in the same firefox window.
In Chrome driver, new links open in the same window itself.
You can force selenium webdriver to open a link in the same window but to open the link in same tab I don't think you can force it directly without injecting some Javascript. Using Javascript you can update the attribute target to complete your requirement.
If you want to inject Javascript you can use JavaScriptExecutor from Selenium Webdriver API.
((JavaScriptExecutor)driver).executeScript("document.getElementById('ID').setAttribute('target', 'self');")
For single-dom element
#driver.execute_script("document.querySelector('your_css_element')[#{index}].setAttribute('target','_blank')")
For multi-dom elements
your_list_of_elements.each_with_index do |elem, index|
#driver.execute_script("document.querySelectorAll('your_css_element')[#{index}].setAttribute('target','_blank')")
end
(note: the above is a ruby snippet, apply the same in your preferred lang.)
WebDriverManager.firefoxdriver().setup();
FirefoxOptions options = new FirefoxOptions();
options.addPreference("browser.link.open_newwindow", 1);
driver = new FirefoxDriver(options);
I have done a fair amount of googling and Selenium does not seem to natively support the clicking of the Save button in pop-up box. However I see a workaround which sets the browser preferences in this question -- Access to file download dialog in Firefox
The code given there is as below --
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("browser.download.folderList",2);
firefoxProfile.setPreference("browser.download.manager.showWhenStarting",false);
firefoxProfile.setPreference("browser.download.dir","c:\\downloads");
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv");
WebDriver driver = new FirefoxDriver(firefoxProfile);//new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
driver.navigate().to("http://www.myfile.com/hey.csv");
Unfortunately, I cannot navigate to the file location, shown in the line below, since it redirects me to the login page of the website.
driver.navigate().to("http://www.myfile.com/hey.csv")
I have already logged-in to the website and log-in again does not make sense. Even for that I have to open a new window handler and switch to the new window(I don't think it will work anyway, since after login it directs to the previous page from which the pop-up occurs ). Is there some workaround to avoid this
driver.navigate().to
and somehow click on the Save button on the pop-up dialogue box?
Note1: When I manually open my browser, The pop-up window does not appear at all. The file starts to download when I click on the previous link even when I don't change firefox preferences manually to automatically download the file.
Note2: I Changed the Firefox preferences manually to automatically download the file types (XML in my case), but Selenium does not pick up this preference(expected behavior, I guess).
Simply put, it's not possible to interact with anything that's not part of the DOM. You can't make Selenium click on the "Save" button of the browser.
Most of the time it's not a good idea to download a file anyway (at least not when you're just doing UI testing).
Depending on what exactly you want to do with the file I'd suggest finding another way to test that behavior.
I am trying to get Selenium WebDriver to find and use a browser window that is already open before the script executes. I am writting in Java.
I am using selenium-server 2.37.0 and the browser is IE8. I am open to using the Chrome browser as well.
Anyway, I have tried opening a driver instance and then looking for the window handles in the usual way (Set handles = driver.getWindowHandles();) but this only finds the hadle of the window that the driver opened. I have also just tried to switchTo the window by the window cannot be found.
The reason I want to use a pre-opened window is because when I execute my script, for some reason the browser won't let it click a link (It may be because the link is to an https address and sends a username and a token). When the script finishes the webpage won't respond to me manually clicking the link either.
I am able to manualy navigate to the link and click it the link works fine, so my thinking is that I can navigate to the page that I want and then kick of the scripts from there, but I need the webdriver to use this browser window that I used.
I cannot navigate the to link directly with Selenium because the link resided behind a secure server. I have to log in first then click the link and this is where I am having the problem.
Unfortunately, as of 2.37.1 (December 2013), it cannot be done.
There is an official feature request for this in the Selenium project (and it's even the most starred one), but it has not been done yet.
You can identify a browser window by windowHandle and switch between several Windows while testing.
You can print out all existing windowHandles (in your case it might be one) and then access it.
This solution worked for me (using Selenium 3.4.0):
Object[] handles = driver.getWindowHandles().toArray();
String windowHandle = handles[0]+"";
driver.switchTo().window(windowHandle);
After switching to your browser window you should be able to continue your test.
It relys on correctness of your webdriver- if you opened an Edge window the driver you use should be an EdgeDriver.
I am facing a strange issue with is not consistent, no trend observed. Whenever I run my webdriver code (see below)
WebDriver driver = new FirefoxDriver();
A driver/browser window opens up and the actions/steps go on as per my code but strangely, only sometimes an extra window opens up and follows same code/instructions.
My code prints/logs success/fail messages to console and I could see those messages only once even an extra browser window follows my code. And with the single driver.quit() command both the windows disappear.
I am using Firefox driver with Eclipse IDE driven by Java Client library.
Could anyone explain what happening with my code?