想找到链接/文本并单击i

2024-04-25 22:07:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用假邮件生成器工具发送邮件并单击邮件中的链接。。 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>

想找到下面的部分代码吗

^{pr2}$

我尽我所知尝试了所有可能的组合,但没有任何帮助。。 这是我试过的剧本

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"):

Tags: thedivbrowseridbyherehtml邮件
1条回答
网友
1楼 · 发布于 2024-04-25 22:07:05

首先,您应该切换到框架,然后找到其中的元素。在

尝试如下:

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

参考文献:

  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

相关问题 更多 >