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.
Related
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.
After login to my application, sometimes a frame opens, which requires a click on the 'OK' button.
So, I have written the code below which switches to the frame, clicks on the OK button and again switches to default.
driver.switchTo().frame(driver.findElement(By.id("InlineDialog_Iframe")));
driver.findElement(By.id(prop.getProperty("pending_email_close_btn_id"))).click();
driver.switchTo().defaultContent();
But, if frame doesn't appear then code gives error saying that the frame doesn't exist.
Please let me know how can I check whether the frame exists or not by using 'if' loop or by any other method?
Thanks.
hi there i had to do some stuff in the past regards to iframes as well and it was very confusing for me as well,
so the very first within you need to understand is that the iframe is actually a web page "inside other web-page" due so you will need to switchTo().frame(...stuff..) to be able to do something
than when you finish you need to get the initial frame driver.switchTo().defaultContent(); so you king of move from one page to the other
regards to find the element which you are after in the iframe i suggest you find any element which will always be present and wrap it with a try
i also suggest you to create a class which will hold your code and wait for JS, Angular, Jquery ...
example from my code:
try {
driver.switchTo().frame(driver.findElement(By.cssSelector("iframe[id^='xdm_default']")));//change focus to iframe
wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.tagName("html"))));//wait for html in the iframe
WebElement divCardsGrid = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.cssSelector("div[class^='CardsGrid']"))));
if (!divCardsGrid.findElements(By.tagName("a")).isEmpty()) {//check for external links
} catch (WebDriverException e) {
log.error(e.getMessage());
}
//change the focus to the initial frame
driver.switchTo().defaultContent();
I hope that helps
List<WebElement> iframes = driver.findElements(By.tagName("iframe"));<br/>
if(iframes.size() > 0)<br/>
{<br/>
// Frames is Present <br/>
driver.switchTo().frame("a077aa5e"); //switching the frame by ID<br/>
driver.findElement(By.id(prop.getProperty("pending_email_close_btn_id"))).click();<br/>
driver.switchTo().defaultContent();<br/>
}else{<br/>
// No Frames <br/>
driver.findElement(By.xpath("html/body/a/img")).sendKeys(“----------”);<br/>
}<br/>
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")));
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?
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.