WebDriver chrome: can not close print dialog
Tried:
driver.switchTo().window(printWindowHandle);
WebElement element = driver.findElement(By.xpath("//body"));
Thread.sleep(5000);
element.sendKeys(Keys.ESCAPE);
// also tried
driver.close();
Already looked at other related questions at SO.
Related
How to open a new tab in same session, I have already tried common solution given by others but its not working.
I am trying in chrome browser.
My project is in java
To open a New Blank TAB you can use the following line of code :
((JavascriptExecutor) driver).executeScript("window.open('','_blank');");
To open a New TAB with url you can use the following line of code :
((JavascriptExecutor) driver).executeScript("window.open('http://facebook.com/');");
I am trying to select Status form a new windows popup. After clicking the select status button it opens the dialog page but i can't see the HTML of that page. So not sure how to interact with that dialog page from selenium.
NB: I have switched to the new window but can't proceed from there.
HTML looks like this..
After clicking the select Status button following dialog page opens.
but i can see the html of the dialog page so how to interact with it form selenium?
Update -14/09/17
When i click on Select Status it call the below url. Opened the url in a separate tab and was able to see the HTML.
http://xxx.xxx.xxx.int/tasks/status.aspx?CurrFilters=OPEN
Tried to select a values from the new windows like below...
public void SelectStatus()
{
_SelectStatus.Click();
Browser.Switch_to_child_page();
_container.FindElement(By.CssSelector("input[onclick^='SelectAll']")).Click();
}
getting following error.
Test 'x.RegressionSuite.TestCases.xTest.TC_x' failed:
OpenQA.Selenium.StaleElementReferenceException : Element is no longer
valid
It looks like new windows popup. you can switch to new window. then interact with it.
// Store the current window handle
String winHandleBefore = driver.getWindowHandle();
// Perform the click operation that opens new window
// Switch to new window opened
for(String winHandle : driver.getWindowHandles()){
driver.switchTo().window(winHandle);
}
//select the checkbox
driver.findElement(By.xpath("xpath for checkbox")).click();
//click on select button
driver.findElement(By.xpath("xpath for submit")).click();
// Close the new window, if that window no more required
driver.close();
// Switch back to original browser (first window)
driver.switchTo().window(winHandleBefore);
I am trying to click on a button on a website using Selenium Webdriver python and I see the button getting highlighted, but not getting clicked using click() function.
Below is the html code for the button I am trying to click
a id="btn_Reset" class="top_btn" onclick="Reset();" href="#">Reboot< /a
I am trying to click on the button using id
inputElement = driver.find_element_by_id("btn_Reset").click()
I also tried xpath with same result
inputElement = driver.find_element_by_xpath("/html/body/div[8]/div/div[2]/div[1]/ul/li[3]/a").click()
Perhaps it's a silly matter of doing it this way:
inputElement = driver.find_element_by_id("btn_Reset")
inputElement.click()
I have a test where I need to open a link in a new tab. This must work in Firefox and Chrome. I first tried it with the Gmail link on the Google page.
On Firefox it works perfectly, Gmail is opened in a new tab.
But on Chrome the Gmail page is opened in the same window and the menu remains open after right click. Has anyone come across this problem?
Beneath is my sample code.
Firefox code:
FirefoxProfile myprofile;
ProfilesIni profile = new ProfilesIni();
myprofile = profile.getProfile("SeleniumAuto");
WebDriver driver = new FirefoxDriver(myprofile);
driver.get("http://www.google.com");
driver.manage().window().maximize();
Actions a = new Actions(driver);
WebElement e = driver.findElement(By.xpath("/html/body/div/div[3]/div[1]/div/div/div/div[1]/div[2]/a"));
a.moveToElement(e);
a.contextClick(e).sendKeys(Keys.ARROW_DOWN)
.sendKeys(Keys.ENTER).build().perform();
Chrome code:
ChromeOptions options = new ChromeOptions();
options.addArguments("--test-type");
WebDriver driver = new ChromeDriver(options);
driver.get("http://www.google.com");
driver.manage().window().maximize();*/
Actions a = new Actions(driver);
WebElement e = driver.findElement(By.xpath("/html/body/div/div[3]/div[1]/div/div/div/div[1]/div[2]/a"));
a.moveToElement(e);
a.contextClick(e).sendKeys(Keys.ARROW_DOWN)
.sendKeys(Keys.ENTER).build().perform();
I've encountered the same issue. Apparently, ARROW_DOWN won't work, so I tried using the keys combination and it works for me. The code is as follows:
1) opening in a new tab with focus still on current tab
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(your_path)));
actions.keyDown(Keys.CONTROL).perform();
driver.findElement(By.xpath(your_path)).click();
actions.keyUp(Keys.CONTROL);
2) opening in a new tab and moving to the new tab
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(your_path)));
actions.keyDown(Keys.CONTROL).perform();
actions.keyDown(Keys.SHIFT).perform();
driver.findElement(By.xpath(your_path)).click();
actions.keyUp(Keys.SHIFT);
actions.keyUp(Keys.CONTROL);
Hope this helps.
Yes, you can do that easily using Selenium. Use the Key commands (Ctrl +T) to open a new tab and then use Ctrl +Tab (Ctrl +\t) command to switch to newly opened tab and perform whatever is necessary. It would go something like this
//open a new tab
WebElement e= driver.findElement(By.cssSelector(abc)).sendKeys(Keys.Control + "t");
//switch control to new tab
e.sendKeys(Keys.Control + "\t");
{
perform some function here
enter code here
}
//switch back to old tab
e.sendKeys(Keys.Control + "\t");
This will work if the browser only has two tabs open, because then it will use the Tab key to move between the two open tabs.
Hope this helps.
For Chrome try this:
Actions a = new Actions(webdriver);
WebElement e = webdriver.findElement(By.xpath(your_path));
a.moveToElement(e).keyDown(Keys.CONTROL).click().build().perform();
I work on selenium automation, we recently updated our selenium jars to latest selenium version and also updated firefox and chrome to latest,
we have one usecase where on clicking on the ESC key we can close the pop-up.
But the key pressing doesn't works in both the browser.
are u sure clicking ESC button Manually closes POPUP????
if robot class fails try this
driver.findElement(By.name("LOCATOR")).sendKeys(Keys.ESC);
Robot class is far better than using SendKeys
(OR)
if it is an alert box try this code you can handle POPUP by using this
try{
Alert alert = driver.switchTo().alert();
alert.accept();
}
catch(NoAlertPresentException e)
{
/****/
}
Hope it helps you
-Ajay