-4

I am using fake mail generator tool to send a mail and click on a link in the mail.. enter link description here

<iframe id="emailFrame" frameborder="0" width="100%" height="360px" src="http://www.fakemailgenerator.com/email/dayrep.com/testlk/message-108204614/" scrolling="no" onload="autoResize('emailFrame')">
 <html>
  <head>
   <body>
    <div>
     <p>Good day - </p>
     <p>You have been assigned an Action from the motion A Name iwhirxpppk: s.    
     </p>
     <p>Kindly follow - up on the Touchpoint Action listed below.
     </p>
     <ul>
     Please click the below link to complete your Action.
     <p>
      <a target="_blank" href="http://cfn- svr001.cloudapp.net:7100/Home/ActionResponse?eid=ygfWFB5a99mtAUQBxjNUDHjpC9AdFz/9&tpid=14iwlvior8ak6FGifOI3MSBNxnNvHiT9">Click here
      </a>
     </p>
     This email has been generated from CFN Insight by Auto man, auto@
    </div>
   </body>
  </html>
</iframe>

want to find below part of the code

<p>
    <a target="_blank" href="http://cfn-svr001.cloudapp.net:7100/Home/ActionResponse?eid=ygfWFB5a99mtAUQBxjNUDHjpC9AdFz/9&tpid=14iwlvior8ak6FGifOI3MSBNxnNvHiT9">Click here</a>
</p>

I tried all possible combinations what ever I know but nothing helped me.. Here are the scripts which I tried

browser = webdriver.Firefox() # for b in
browser.find_element_by_id('emailFrame').find_elements_by_xp‌​ath(".//*"):
    print b # browser.find_element_by_xpath("html/body/div[1]/p[4]/a") #
    browser.find_element_by_xpath(".//*[text()='Click here']") # 
    browser.find_element_by_xpath[".//a[contains(., 'Click here')]"] # 
    browser.find_element_by_xpath(".//div[1]//p[4]/a") 
    browser.find_element_by_id('emailFrame').find_elements_by_ta‌​g_name("a"):
Guy
  • 46,488
  • 10
  • 44
  • 88
Lalit
  • 43
  • 2
  • 3
  • 10
  • want to automate the part

    Click here Here are the scripts which I tried but nothing helped me.. browser = webdriver.Firefox() # for b in browser.find_element_by_id('emailFrame').find_elements_by_xpath(".//*"): print b # browser.find_element_by_xpath("html/body/div[1]/p[4]/a") # browser.find_element_by_xpath(".//*[text()='Click here']") # browser.find_element_by_xpath[".//a[contains(., 'Click here')]"] # browser.find_element_by_xpath(".//div[1]//p[4]/a") browser.find_element_by_id('emailFrame').find_elements_by_tag_name("a"):

    – Lalit Dec 15 '16 at 10:52
  • Possible duplicate of [Selenium and iframe in html](http://stackoverflow.com/questions/18924146/selenium-and-iframe-in-html) – JeffC Dec 15 '16 at 18:59

1 Answers1

0

First, you should switch to the frame and then find the element inside it.

try as follows:

from selenium import webdriver
from selenium.webdriver.common.by import By

browser = webdriver.Firefox()
browser.maximize_window()
browser.get("http://www.fakemailgenerator.com/inbox/armyspy.com/morly1985/")
frame = browser.find_element(By.ID, 'emailFrame')
browser.switch_to_frame(frame) # switch to frame by finding the iframe webelement
click_here = browser.find_element_by_xpath(".//*[text()='Click here']") # try different xpaths.
click_here.location_once_scrolled_into_view # As the element needs scroll down
click_here.click()

References:

  1. https://stackoverflow.com/a/40759300/2575259
  2. http://selenium-python.readthedocs.io/navigating.html#moving-between-windows-and-frames
  3. http://selenium-python.readthedocs.io/api.html
Community
  • 1
  • 1
Naveen Kumar R B
  • 6,248
  • 5
  • 32
  • 65
  • Already tried the scripts suggested by Naveen but didn't work. Identifies browser.switch_to_frame('emailFrame') but not browser.find_element_by_xpath(".//*[text()='Click here']") – Lalit Dec 15 '16 at 14:51
  • updated the code. try it out. how do you know switching to frame worked? what is the exception for finding `Click here` element? – Naveen Kumar R B Dec 15 '16 at 15:05
  • what is the exception? is it failing when finding the frame? or finding the element? trace is needed to further help you – Naveen Kumar R B Dec 16 '16 at 06:55
  • Hi Naveen, Sorry to say, I updated the code and tried but no luck The purpose is, it is basiccaly a link and clicking on the link (Click here) will open another window(/tab) Here is one page link (http://www.fakemailgenerator.com/inbox/armyspy.com/morly1985/) on I want to find the "Click here" link – Lalit Dec 16 '16 at 06:57
  • Able to find frame but not finding the element? – Lalit Dec 16 '16 at 07:00
  • please add the full code. I am confused about the flow as I don't see browser.get method. add the trace, I'll try find out what is the issue. – Naveen Kumar R B Dec 16 '16 at 07:03
  • Can you please visit the link - fakemailgenerator.com/inbox/armyspy.com/morly1985, from this page I want to find the click link – Lalit Dec 16 '16 at 10:07
  • tried it. the issue seems to be with the scroll. updated the answer. try. – Naveen Kumar R B Dec 16 '16 at 10:33