Selenide - How to handle gmail pop up in chrome - java

I am trying to switch to a Gmail login popup that appears on clicking a button on my chrome. When I do a driver getWindowHandles(), it shows only one window - the parent. Also I noticed in the taskbar that the popup that opens has a google/gmail icon instead of chrome browser icon which is why I am assuming that the Webdriver does not count it as a second open "chrome" window, but instead a different one altogether.
So far I have tried everything on the driver methods
driver.switchTo().window(1 or 0)
Any suggestions would be helpful!!

driver.switchTo().alert().anyMethod
can be used.

First of all, why are you using driver. with Selenide? Selenide has a static WebDriver call - getWebDriver() (if really needed) with the next import import static com.codeborne.selenide.WebDriverRunner.getWebDriver;
From your quesiton, it is not clear what you want - either its pop up that appears after clicking or you want to switch to another chrome tab window?
If its a pop up alert, then the next code should help (to accept it for example):
getWebDriver().switchTo().alert().accept();
If you want to open a tab or focus on it:
switchTo().window(1);

Related

Page is unclickable after closing a window

My flow is as follows in selenium:
Access a webpage
Click a tab
Click on add button in a tab where a window would open
Close that window
Click on that same tab again
I'm able to go through steps 1 to 4 without issues however at step 5 i'm not able to click the tab element knowing that i've clicked that same tab at step2, I did check from console and the same xpath I used in step2 did not return any element however when i clicked on that element to inspect it in console it started returning some values in console but still didn't work from selenium when i continued the run (in debug)
My page is in an Iframe which i was successfully able to access and print page title after step 4 but my issue remains, why aren't i able to click that tab from selenium after i close the window and the screen refreshes, why are the elements unresponsive anymore?
After doing some research i also tried the below script:
WebElement element=driver.findElement(By.xpath(the_path));
JavascriptExecutor ex=(JavascriptExecutor)driver;
ex.executeScript("arguments[0].click()", element);
but it would fail at the first line since the element is not fount, tried to initialize it earlier in the code but then it would fail at line 3.
How do i fix this issue?
Try to click on the element using Selenium code, not by injecting JavaScript to the pages. This should solve your problem.
WebElement element = driver.findElement(By.xpath(the_path));
element.click();
The issue was due to having multiple Iframes in the main page, so when closing switching windows I was not redirected to the proper Iframe in which i was in step 3 when clicking the tab.

New Tab Navigation is Sometimes Not Loading the Page, Why?

My Java Selenium WebDriver script clicks a link in a web page that opens a new tab and navigates to an external site. There are multiple of these links to different social media.
The problem I have is that sometimes the new tab opens and tries to load the external page but stops all together.
I figured this isn't a big deal, I will just refresh the page with my code like I would manually in the browser and it will attempt to reload the page. I was wrong.
Evidently, perhaps in Chrome only, the reload/refresh functionality included with Selenium and even JavaScript does not work the same as clicking the refresh button. In this circumstance, they do nothing at all.
Luckily, this only happens every now and then but it does cause my test to fail when it does happen.
When this happens, the title area of the tab says "untitled", the page is blank white with nothing on it, and the desired URL will be in the address bar. Only manually clicking the refresh button will reload the page properly.
I haven't seen this happen in Firefox even once so I am going to assume it is only an issue in Chrome.
Does anyone know how to work around this issue?
Here is what I have tried in JavaScript:
document.location.reload(false);
document.location.reload(true);
I tried these in Java Selenium:
driver.navigate().refresh();
public Actions act = new Actions(driver);
act.keyDown(Keys.CONTROL).sendKeys(Keys.F5).keyUp(Keys.CONTROL).perform();
I should also say that these refresh methods work normally when the page is working normally. It is literally this one situation where they do not and I don't know what to do. Is there no way to programmatically click the refresh button in the browser? I need to find out if I can move the mouse and have it click.
Might be chrome web driver issue. try updating to latest.
driver = new ChromeDriver();
driver.manage().window().maximize();
baseUrl = "http://www.google.com/";
driver.get(baseUrl);
driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"t");
ArrayList<String> tabs = new ArrayList<String> (driver.getWindowHandles());
driver.switchTo().window(tabs.get(1)); //switches to new tab
driver.get("https://www.facebook.com");
driver.switchTo().window(tabs.get(0)); // switch back to main screen
driver.get("https://www.linkedin.com");

Selenium Webdriver Java: Testing Zopim chat functionality

I am trying to test the functionality of a chat window similar to the zopim chat window using Selenium WebDriver Java. After troubleshooting for a longtime, I got to know that it is a different frame altogether in the webpage. So first I tried to open the window with the command pasted below and it worked, but now I am unable to perform any kind of action on the chat window. I am trying to enter the fields and click the button. I am a beginner in Selenium so after 2 days of trying on this issue but in vain. Kindly help! Thanks
Website: https://www.zopim.com/
The minimzed button on the right hand side corner at the bottom in green color "Leave us a message"
driver.switchTo().frame(driver.findElement(By.cssSelector("iframe[src='about:blank']")));
//click the iFrame
new WebDriverWait(driver, 20).until(
ExpectedConditions.elementToBeClickable(By
.xpath("//div[#class='meshim_widget_widgets_Favicon favicon']"))).click();
It's just that you are locating a different iframe. You have to improve your locator:
driver.findElement(By.xpath("//iframe[.//textarea[#name='message']]"))
Here we are locating the iframe having the textarea element with name="message" - our chat message text field.

Selenium Webdriver iframe interactions are inconsistant

When I enter an iframe (to provide Credit Card Details) using
driver.switchTo().frame(iframe);
It does its job correctly and filling in the form in the iframe and I switch out of the iframe using
WebElement ccInfo = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath(".//*[#id='paymentech_form']/div/button"))));
ccInfo.click();
driver.switchTo().defaultContent();
However, the behavior of the function is inconsistent. The problem is when I am running the test in the background (minimized or hidden window) it always fails to click on the button mentioned above while the rest of the form is filled in. This problem does not prevail when I have the window open and selected.
Is there a possible work around for this?

How to get object of Pop-up screen that blocks the main screen using firepath in selenium webdriver?

I am writing an automation script in Java in selenium webdriver. When I try to logoff my main window screen I am getting a pop-up window that does not allow me to go to the main screen unless I click some option "Leave page" or "Stay on page" . Can I get the script to close this screen and logoff the main application.Firepath does not work for this as well. I am a beginner trying to learn automation.Thanks.
Adding some of your code to the question would be useful...
Here is a wild guess, assuming that you have a WebDriver driver instance:
driver.switchTo().alert().accept(); // Leave Page
driver.switchTo().alert().dismiss(); // Stay on page
Try these first:
driver.switchTo().alert().accept(); // to leave page
or
driver.switchTo().alert().dismiss(); // to accept page
if doesn't work, then you can use Robot class to press Enter or any Key like -
Robot robot = new Robot();
robot.setAutoDelay(3000);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
Only thing you've to notice - which button the default cursor or which one is highlighted, Robot will perform action on the highlighted object only, from there you can press tab to go anywhere else.
Hope this helps.

Categories