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?
Related
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);
I'm trying to sendKeys in the textfield inside form. But this form is put in the link. Attribute src refers to that link.
Here's the code
How could I reach textfield inside the link, because this link is in iframe and fancybox.
You have to switch the focus of the driver to the iFrame. You can use the below to switch to the iFrame
driver.switchTo().frame(driver.findElement(By.id("ID of your iFrame")));
Once it has switched focus you can perform the actions you need to within the form, and when you are done with the form you have to switch back out of the iframe and back onto the page using the below -
driver.switchTo().defaultContent();
I am trying to write some UI test cases for an SAP-webUI (web based) application. After login, it shows the dashboard ( Workcenter's ) screen.
Now the problem is, I am able to open the page, enter U/N, Pwd and login through Selenium. After i press the "Login" button the URL changes and the page got redirected/refreshed.
E.g. URL before login : https://a/b/c/d/e/f/g.htm?sap-client=001&sap-sessioncmd=open
E.g. URL after successful Login : https://a/b(bDsdfsdsf1lg==)/c/d/e/f/g.htm
After this im unable to perform any action or press any link in any part of the page. I tried with all the possible attributes ( css, xpath, id ). Webdriver was unable to find any element on the page. It shows the error "No element found" alone.
I am using java with Selenium Web Driver.
Please find the html structure of the webpage below
<html><body><div><div><iframe>#document<html><head></head><frameset><frameset><frame>#document<html><head></head><body><form><div><div><table><tbody><tr><td><div><ul><li><a id=abcdef></a></li></ul></div></td></tr></tbody></table></div></div></form></body></html></frame></frameset></frameset></html></iframe></div></div></body></html>
Actually i want to click a linkmenu "abcd", which is inside iframe and frame as shown in the below HTML code
<html><head></head><body><iframe name=a1><html><head></head><frameset><frameset name=fs1><frame name=f1><html><head></head><body><table><tbody><tr><td><ul><li><a id=abcdef>
I tried the below code as well.
driver.switchTo().frame("a1");
driver.findElement(By.id("abcd")).click();
OR
driver.findElement(By.xpath("//*[#id='abcd']")).click();
After using the above code, still im getting the error "No such element"
Kindly suggest
Regards,
Siva
Do it this way...
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[#name='a1']"))); // switching to iframe
followed by
driver.switchTo().frame("f1"); // switch to frame
and then your desired action...
driver.findElement(By.id("abcd")).click();
This is because of the iframe. You need to switch to it first:
driver.switchTo().frame(0);
driver.findElement(By.id("abcdef")).click();
where 0 is a frame index.
See doc on implicit wait here
I guess you should do a implicit wait until your chosen element is available
modify these code to suit your chosen element:
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));
I am trying to write a WebDriver test for the following site for learning purposes: http://www.mate1.com
On clicking the login link, I get a form to fill in my email id and password. As far as I understand, the form is shown in an iframe.
To enter the credentials, I tried to identify the number of iframes for that particular page (and found it as 7) and tried switching in to each iframe and search for the email field by XPath and the ID. However, I wasn't successful to find it. So how can this be done?
This is my code:
driver.get("http:www.mate1.com");
driver.findElement(By.xpath("//*[#id='header-container']/div/a")).click();
List <WebElement> frames = driver.findElements(By.tagName("iframe"));
System.out.println("Totalframes -> "+ frames.size());
driver.switchTo().frame(0);
driver.findElement(By.xpath("//[#id='email']")).sendKeys("xxxxxxxxx#rocketmail.com");
This is likely a good situation to use switchTo().frame(WebElement):
driver.switchTo().frame(findElement(By.cssSelector(".iframe-container>iframe")));
The login and password fields are not in an iframe, you can directly use the following code -
driver.findelement(By.id("email").sendKeys("xxxxxxxxx#rocketmail.com");
Try not to switch to any iframe and execute the above line, this will work.
I'm trying to make a auto sending mail throw hotmail with webdriver 2.
I'm using WebDriver, with java and eclipse.
I'm curreently succeed to get in hotmail by login, and i got the main mail page.
Now i have to click the "New" button (image number 1),
And when i click it by the command : driver.findElement(By.id("NewMessage")).click();
It's working and the page moving to the next compose page (Image number 2).
But WebDriver thinks he still at the previous page from some reason.
I can't click on any element on this page.
My target is to send keys to the "To" field, but i can't get it.
As you can see in image number 2, I tried to get the element by the "InputBox" class, the id, by className, xpath, etc.
I will be happy if someone can help me..
Thanks,
Or.
The problem is the To field is in the iframe. In selenium if you want to do any action in a frame mean first you have to get in to the frame.
Code to enter the frame:
//Assume driver is initialized properly
driver.switchToFrame("Frame Name");
(Or)
driver.switchTo.frame("FrameIndexValue");
(Or)
WebElement element = driver.findElement(By.id(LocatorValue));
driver.switchTo.frame(element);
//Do any action inside the frame
After you finished the action inside the frame you have to get out of the frame to do any action outside the frame.
Code to Leave Frame:
//driver.switchTo.defaultContent();
If you are dealing with the iframe then the defaultContent() will take you to the main page above all the iframes, but if you deal with the frame this method will take you to the first frame of the page.
For more info on frmae handling.