Selenium Webdriver Java: Testing Zopim chat functionality - java

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.

Related

"I'm not a Robot" Recaptcha is not working as expected -Selenium WebDriver(Java)

Steps to Produce:
I am trying to handle "Recaptcha" through manual intervention using Selenium Web Driver (Java) in Firefox Browser
In the demosite,"https://demoqa.com/register", I am trying to automate "Recaptcha" through manual intervention
I am switching into "I'm not a Robot" frame and trying to click on the checkbox and then use "Explicit Wait" till I manually click on "Verify" button
Then I am switching out of the iframe to the default content and trying to click "Register"
Issue:
My code works till switching into "I'm not a Robot" frame and the random image tiles open, then it doesn't work
My Code:
//Check "I'm not a Robot"
driver.switchTo().frame(7);
driver.findElement(By.xpath("//span[#id='recaptcha-anchor']/div")).click();
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(15));
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(
By.xpath("//iframe[starts-with(#name, 'a-4fg5nocuvnax') and starts-with(#src, 'https://www.google.com/recaptcha')]")));
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("#recaptcha-verify-button"))).click();
driver.switchTo().defaultContent();
Help me and correct if I am wrong .

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.

Selenide - How to handle gmail pop up in chrome

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);

xpath for customer id in hdfc net banking page[Selenium Webdriver] [JAVA]

I am trying find xpath for customer id for the following website-
https://netbanking.hdfcbank.com/netbanking/?_ga=1.219943581.521154242.1455311784
I have tried various XPath's such as -
1.//input[#class='input_password']
2.html/body/form/table[2]/tbody/tr/td[2]/table/tbody/tr[1]/td[1]/table/tbody/tr[3]/td[2]/table/tbody/tr[2]/td[2]/span/input
But none of them seem to be working. I am using selenium webDriver to sendkeys
for eg '123456' to that customer id box and hit continue button.
But selenium is not able to find the element everytime. Can somebody please help me with that!
The text box is inside frame, you need to switch to it first
// switch to the frame
driver.switchTo().frame("login_page");
// find the text box and write to it
driver.findElement(By.className("input_password")).sendKeys("123456");
// switch back to main window
driver.switchTo().defaultContent();

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?

Categories