When a link is clicked manually in my application, it opens in new tab in Chrome and IE.However when my script is run, the link opens in a new window in IE instead of new tab. Same script runs as expected in Chrome.
Has anyone faced this issue?
When a link is clicked, I understand your test script has code to just do
element.click()
which opens the link in new tab.
If yes, its upto the app code to open in a new tab or new window. and if it is working in Chrome and not in IE, its nothing to do with your Selenium Test script.
You got to check with your developer to troubleshoot it. I hope it answers your query.
Related
As per Difference between webdriver.Dispose(), .Close() and .Quit()
driver.close closes the current active window where driver.quit closes all of the windows. What I get is if I opened a new tab in my current window and then called driver.close the whole windows including my tabs would close. But when I run that code
driver.get("http://testingpool.com/selenium-ide-part-1/");
driver.findElement(By.xpath("//*[#id='content']/div[2]/article/div/div[2]/div[1]/p[8]/span/a")).click(); //opens a new tab
ArrayList<String> allWindowHandles = new ArrayList<> (driver.getWindowHandles());
driver.close()
only the first tabs gets closed. Also I find that my allWindowHandles has length of 2 although I have only one window.
I was trying to open a new window using Selenium as per https://www.tutorialspoint.com/how-to-open-a-new-window-on-a-browser-using-selenium-webdriver-for-python using
((JavascriptExecutor)driver).executeScript("window.open('')");
but that resulted in a new tab not a new window.
I am confused if Selenium differentiates between a tab and a window at all or not.
With the terminology used to distinguish between driver.close() and driver.quit() methods supported by Selenium WebDriver in the post you are referencing to, they actually mostly mean browser tabs, not windows.
By opening a new browser window with
((JavascriptExecutor)driver).executeScript("window.open('')");
or by clicking on some web element opening a new browser tab/window is will normally open a new tab in the existing browser.
What I get is if I opened a new tab in my current window and then
called driver.close the whole window including my tabs would close.
But when I run that code
See you may have opened a new tab by clicking on link or using JavascriptExecutor but Selenium still has focus on first tab of the first window.
Therefore, when you do this:
ArrayList<String> allWindowHandles = new ArrayList<> (driver.getWindowHandles());
driver.close()
It should close the first tab or window, since you have not switched to new tab/window.
Also I find that my allWindowHandles has length of 2
this is cause you have opened a new tab using this line
driver.findElement(By.xpath("//*[#id='content']/div[2]/article/div/div[2]/div[1]/p[8]/span/a")).click(); //opens a new tab
the moment you open a new tab by clicking on a link or Using JavascriptExecutor, you will have +1 windows handle.
However, if you do not switch to any tab or window/s. Selenium will always have focus on first tab of the first window.
Also, window.open('') is Js command not Selenium.
there is a difference between a new tab or windows. But if you take Selenium into consideration, We switch to new tab or windows in a same way.
However to open a new window, you would have to simulate CTRL+N keyboard action.
I am trying to open a new tab in IE 11 by clicking on a link but instead it opens a new window for when clicking on a link. I googled for proper way of doing it but cant figure out how to achive that. Can any one please help?
While clicking manually link opens in a tab but when doing in by selenium it opens a new window.
I am not adding any code as there is not much to add . I clicked link element using webElement.click() and i have disabled persistentHover in driver capability and I am using selenium with java.
String openInNewTab = Keys.chord(Keys.CONTROL,Keys.RETURN);
webElement.sendKeys(openInNewTab);
I am facing below described issue while automating the application using selenium webdriver:
When I click on a link a new window should pen with the contents of that window, but when I click on the link new window is opening with login screen, what may be the issue, can anyone help me in this regard.
This issue is only with automation (manual click always works), but sometimes works.
Thanks in advance
Sounds like when a new window opens, all of the session cookies from the previous window are not being transferred. In this situation I would put a try catch block to login again if the login window appears.
I am using selenium web driver using phpunit, the problem I am facing right now is that I have a link button and when I click this button the current link is opened in a new page and I have no idea about how to oen the currently opened new page, can some one help me about how can I code in PHPUnit to open the currently new opened page
Use "WindowHandles" in PHPunit function
Here is the solution to navigate between the tabs:
If there are two opened tabs in your browser and you want to switch to the next tab, below code will work:
$window_handles = $this->windowHandles();
$this->window($window_handles[1]);
And if you want to switch back to the previous tab just change the index as shown below :
$window_handles = $this->windowHandles();
$this->window($window_handles[0]);
I'm using the Selenium Client drivers to run tests built in C#. I'm having a problem where the test navigates to a page and clicks on a button in a form with its target set to _blank causing it to open a new window. However the new page being opened returns an XML document and not a typical webpage. Selenium seems to have trouble with this because it hangs when the button is click and the new window opens. No instructions after the click method are executed. The test eventually fails with the error Timed out running command.
Any help/guidance would be appreciated. I've scoured the net but haven't seen anyone running into this particular issue of the page being opened not being a typical webpage which I think is the core of the problem as Selenium can't really manipulate this new opened window. I would post code except that literally all I'm doing is calling the click method on a button which causes a new window to open. Thanks in advance.
To tackle the issue of opening in new window. I typically get url of the link which is to be opened and instead of using selenium.click(), I use:
selenium.open("http://yourwebsite/yourlink")
This helps me to be on the same window only(which avoids opening new window or tab) and when the testing is finished on this page and you want to switch back to original page you can again use:
selenium.open("http://whatever/")