I have the next situation:
I'm running Automation in MacOS with Selenium in Safari.
I want to take control over a new tab opened (Switch to a new tab in Safari)
I'm able to do it with Chrome and Firefox, but in Safari does not work.
The next code is what I'm using for that:
//Store the parent window
String parentWindow = driver.getWindowHandle();
//Open a new Windows(Mailtrap)
String a = "window.open('https://mailtrap.io/signin','_blank');";
((JavascriptExecutor)driver).executeScript(a);
//Take control over new browser
for(String handle: driver.getWindowHandles()){
driver.switchTo().window(handle);
}
//Make the same actions over new window
driver.manage().window().maximize();
driver.switchTo().defaultContent();
After that...
//Close window and back to the parent window
driver.close();
driver.switchTo().window(parentWindow);
driver.switchTo().defaultContent();
As I told before: It works in Firefox, Chrome, IE11, but in Safari 12.0.3 this is the message when I do a manual click over a tab.
"This Safari window is remotely controlled by an automated test."
To interact with this Safari window, you need to stop the current automated test session.
You should not use this window for normal web browsing.
"Turn OFF All Automation" , "Stop Session", "Continue Session"
Could anybody help me with this?
PS: Develop --> Allow remote automation is selected.
As the automation speed is very fast on Safari, the only solution for this was the "old friend forever":
Thread.sleep
That was the only solution, because the Implicit and Explicit waits were not working.
Related
Problem Statement: We have to automate a scenario where action traverse between windows and web based pages.
We use SikuliX and Selenium 3.141.
Issue is I always land on main home page but the requirement is to land on previously launched web page.
1.Open webpage1 (main home page)
2.Perform action and close webpage.
3.Focus on windows action (Sikuli), perform and close.
4.Switch back to webpage > opens main home page, create some object (lands into app home page) and close.
5.Switch to windows action (Sikuli), perform and close.
6.Lastly, switch back to webpage,expectation is to land on 'app home page' but I land on main home page.
Is there a possibility to land into app page or subpages in selenium than main home page always.
Please review snippet.
'''//Open selenium
commonLibrary.login(); //opens webpage1
commonLibrary.getCookie();
driver.close(); //close webpage of selenium
//Close selenium
//Open Sikuli
s.click("C:\\APMWS\\testmvnproject\\src\\imagelibrary\\images\\start.png"); //Close Sikuli
//Open selenium
commonLibrary.setBrowser("browser");
commonLibrary.navigateToUrl("url");
commonLibrary.setCookie();
commonLibrary.navigateToUrl("url"); //again set url with new cookies
driver.findElement(By.xpath("//*[contains(text(),'View My Company')]")).click(); //opens webpage 2
commonLibrary.getCookie();
driver.close();
//Close selenium
//Open Sikuli
s.click("C:\\APMWS\\testmvnproject\\src\\imagelibrary\\images\\close.png");
//Close Sikuli
//Open selenium
commonLibrary.setBrowser("browser");
commonLibrary.navigateToUrl("url");
commonLibrary.setCookie(); //we need to send previously stored cookies which we collected and stored before closing browser
commonLibrary.navigateToUrl("url"); //again set url with new cookies
driver.findElement(By.xpath("//*[contains(text(),'Organizational Expenses')]")).click(); //this action exists on webpage 2 above, but I land on webpage 1
//Close selenium
'''
Usecase:
1. Login to webpage and store cookie information.
Close the session.
Switch to windows action in Sikulix, perform some action and close.
Now, again switch to webpage by reading cookies stored.
It directly goes to Main home page without logging-in.
Perform some create action of part which will take the control of selenium to Part home page.
Store cookies and close the session, switch to Sikuli, perform action and close.
Now, restore cookies and launch webpage.
Expected Result: Browser should open with part home page(sub page).
Actual Result: Browsers opens to main home page.
Here's our routine driver instantiation code
WebDriver driver =new InternetExplorerDriver();
driver.get("http://internal.com");
Let's say that the above opens an instance (window) of IE - Window 1. In this case, we have some JS on internal.com's index.html that opens a new window, say Window 2. The problem is that when we quit the driver, we can easily close Window 1 but we seem to have no control over Window 2.
driver.quit();
Are there any clean ways to close Window 2 and any other derivative browser windows at the end of every test case?
I am creating automated test cases with Selenium WebDriver 2. My code is set up, so that FireBug automatically is opened when Selenium WebDriver opens FireFox. A few seconds later I ask Selenium to close it again. For some reason, if I don't do this, sometimes FireBug won't be available to me at a later stage.
My problem:
When I use the TestNG suite to run my test suite, some of the test cases end up opening FireBug but not closing it again. My guess is, that this is due to existing browser windows already being open. The "close FireBug code" is then misused to open FireBug instead of closing it.
For this reason, I would like to make a check to see if FireBug is open, and if so, I would like to close it.
Opening code:
String firebugPath = TO_Constant.fireBug();
FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(new File(firebugPath));
profile.setPreference("extensions.firebug.showFirstRunPage", false);
profile.setPreference("extensions.firebug.allPagesActivation", "on");
driver = new FirefoxDriver(profile);
Code to close FireBug:
Actions action = new Actions(driver);
action.sendKeys(Keys.F12).build().perform();
I can find ways to do this in javascript, using window.console. Is there any way to do something similar in java?
console.log('is DevTools open?', window.devtools.open);
You can also listen to an event:
window.addEventListener('devtoolschange', function (e) {
console.log('is DevTools open?', e.detail.open);
});
It doesn't work when DevTools is undocked. However, works with the Chrome/Safari/Firefox DevTools and Firebug.
The answer is by Sindre Sorhus and has been taken from here!
Find out whether Chrome console is open
I have written Java code using Selenium Webdriver and AutoIt that opens a Firefox driver, navigates to a page that requires authentication via selection of a soft certificate, selects the appropriate certificate when the Certificate Selection window pops up, and clicks OK, at which point the page I'm accessing should load but instead it just loads a blank "New Tab"; a new tab isn't opened per se, just the current tab remains blank with the title of "New Tab".
If I perform this process manually (without having Selenium Webdriver open a Firefox driver and I just launch it myself) using the same exact Firefox profile, the page loads after authentication just fine. I should also note that the page loads successfully using driver instances of Internet Explorer and Chrome.
I am using Firefox v33.1, IE 10, and Chrome v38. Finally, I should note that this has nothing to do with my automated certificate selection process because even if I only have Selenium Webdriver open a Firefox driver and stop there and then I take the wheel and select the certificate myself and click OK, it still does the same thing.
I think Selenium Webdriver might have some annoying guard built into the Firefox drivers it instantiates that prevents it from loading pages requiring authentication. If this is the case, does anyone know how to possibly disable that?
Java needed to be set to "Always Activate" under the Firefox Add-ons -> Plugins. Before it was set to "Ask to Activate" but it never explicitly asked to activate after I selected the certificate, thus the page wouldn't load.
I've Googled, searched SO, and looked at the Selenium Javadocs but haven't found an answer to this question.
Is there any way, using Selenium WebDriver, to accept those "Share Location" popups that get displayed by browsers (Chrome, Firefox, IE) when a website is trying to track your location?
Also, I'm writing up my Selenium code in Java and using the Selenium Client Drivers.
I've tried running the Selenium IDE (the Firefox add-on) and recording me accepting the "Share Location" popup that Firefox popsup but nothing gets recorded in the Selenium IDE.
If the popup is part of the browser then the answer is no. If you want to interact with something displayed in a second window ( not part of the browser) then yes. There should be a .switch_to method.
Although if you can have this page remember your settings you can load a profile when you create a new instance of the browser.
In windows you can create a profile in firefox by going to the start menu and typing "firefox.exe -p" here you can create a new profile where you you would have a "remember me check box" checked.
As far as loading a profile in Java + Selenium I'm not sure how you would do this. I use Ruby + Selenium and this is how I do it.
$driver = Selenium::WebDriver.for :firefox, :profile => "MyProfile"
hope this helps
I have got the solution to this in firefox but still working on chrome. The below code should help and fetch your exact location on maps:
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("default");
myprofile.setPreference("geo.prompt.testing", true);
myprofile.setPreference("geo.prompt.testing.allow", true);
myprofile.setPreference("geo.wifi.uri", "https://location.services.mozilla.com/v1/geolocate?key=%MOZILLA_API_KEY%");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE,myprofile);
After this just pass the FirefoxProfile instance in the driver method just as below(for the above code):
driver = new FirefoxDriver(myprofile);
That should be fine, write all the other stuff you want and execute!!