selenium RC(python)遇到嵌套iframe问题

时间:2015-10-14 19:35:42

标签: jquery python xml selenium iframe

我试图在python中导航selenium,将文本发送到Indeed网站示例测试页面上的输入字段(单击“应用”以查看包含输入字段名称,电话,电子邮件,求职信等的表单)< / p>

http://www.indeed.ca/cmp/HD-GROUP/jobs/Regional-Representative-a72711272aba6984?sjdu=vQIlM60yK_PwYat7ToXhk40tHzG2V8PFLUkYNu3gUARzMPxmzfYNIZhnUOBL3fqJ0waO2mcYR2CrxwZY5aM-JSDuEjnVcDU8mqRWS8wbyaI

我意识到我需要告诉selenium切换到那个iframe,问题就在那里,实际上是两个。

我有以下XML路径:

//*[@id="indeed-ia-1444850868596-1-modal-iframe"] <-- first iframe

/html/body/iframe <-- second iframe

//*[@id="apply_form"]  <-- form 

输入:

//*[@id="form_container"]/div[2]/div[1]/div[1]/div[1]
//*[@id="form_container"]/div[2]/div[1]/div[1]/div[1]/div[1]/div
//*[@id="phone_container"]
//*[@id="form_container"]/div[2]/div[1]/div[1]/div[1]/div[2]

我如何把这些东西放在一起?

1 个答案:

答案 0 :(得分:0)

这里的想法是点击&#34;立即申请&#34;按钮,等待iframe出现,然后切换到它,然后切换到内部iframe,找到输入框并发送密钥。工作示例:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


driver = webdriver.Chrome()
driver.get("http://www.indeed.ca/cmp/HD-GROUP/jobs/Regional-Representative-a72711272aba6984?sjdu=vQIlM60yK_PwYat7ToXhk40tHzG2V8PFLUkYNu3gUARzMPxmzfYNIZhnUOBL3fqJ0waO2mcYR2CrxwZY5aM-JSDuEjnVcDU8mqRWS8wbyaI")

driver.find_element_by_css_selector("a.indeed-apply-button").click()

wait = WebDriverWait(driver, 20)
frame = wait.until(EC.presence_of_element_located((By.TAG_NAME, "iframe")))

driver.switch_to.frame(frame)
driver.switch_to.frame(0)

driver.find_element_by_id("applicant.name").send_keys("test")