0

I am trying to get the content of the email from site name "yopmail.com" which is having multiple frames. I need to switch to the frame name = 'ifmail' and want to getText from email body.

Please see screenshot for yopmail:

enter image description here

Anyone can help me out here?

Curious
  • 282
  • 4
  • 21

5 Answers5

0

You can give the name as parameter to the switch command

driver.switchTo().frame("ifmail");
Guy
  • 46,488
  • 10
  • 44
  • 88
  • I already tried with below two options but none are working : driver.switchTo().frame("ifmail"); AND driver.switchTo().frame(driver.findElement(By.xpath(".//iframe[@id='ifmail'"))); – Krunal Patel May 03 '16 at 05:54
  • Now able to switch to the frame and able to extract text. – Krunal Patel May 04 '16 at 04:59
0

Hi please handle iframe like below

  1. driver.switchTo().frame(int arg0); // Select a frame by its (zero-based) index. That is, if a page has multiple frames (more than 1), the first frame would be at index "0", the second at index "1" and so on.

    List<WebElement> iframeElements = driver.findElements(By.tagName("iframe"));

    System.out.println("The total number of iframes are " + iframeElements.size());
    
  2. driver.switchTo().frame(String arg0); // Below is the example code snippet using frame a.Name. b.Id. c.WebElement

    driver.switchTo().frame(frame);
    System.out.println("Navigated to frame with name " + frame);
    
  3. Switching back to Main page from Frame

    driver.switchTo().defaultContent();
    

Hope this helps you

Rajnish Kumar
  • 2,828
  • 5
  • 25
  • 39
0

You can switch to frame by name, id, webelement , index

Here the HTML of frame:-

<iframe class="whc" frameborder="0" scrolling="auto" id="ifmail" name="ifmail" src=""></iframe>

You id and name have the same name so you can switch it as below :-

driver.switchTo().frame("ifmail");

OR

driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@id='ifmail']")));

Hope it will help you :)

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
0

i use the below code to get the text of email body:

 Thread.sleep(4000);
 driver.switchTo().frame("ifmail");

List<WebElement> elems = driver.findElements(By.cssSelector("div#mailmillieu>div>div[dir='ltr']>div"));

for(WebElement element: elems){

    if(!element.getText().equals("")){
        System.out.println("body is "+element.getText());
    }

}

i use "" as there are some br and new line in my body. But it will show all the text of ur body.

noor
  • 2,954
  • 2
  • 16
  • 29
0

Please try as below, hope it helps:

//Switch to Main page first

driver.switchTo().defaultContent();

//Switch to the desired frame

driver.switchTo().frame(frame);

// perform steps you want to do

//and then Switching to Main page again

driver.switchTo().defaultContent();

SGT
  • 1
  • 2