如何在硒中与此iframe交互

时间:2015-10-14 06:34:49

标签: python selenium iframe

     <?php
        $filename = "file.csv";
        $fp = fopen('php://output', 'w');           
        header('Content-type: application/csv');
        header('Content-Disposition: attachment; filename='.$filename);
        $headerLine = 'Sr. No,Name,DOB,Address';
        fwrite($fp, $headerLine);
         $query = "select * from registratin";
        $result = mssql_query($query);
        $i = 1;
        while($row = mssql_fetch_row($result)) {
          $row = array_merge(array($i), $row);
          fputcsv($fp, $row);
          $i++;
        }

      ?>

不起作用。

不幸的是,我尝试了检查元素的每个变体,复制xpath,尝试识别文本框的类名等。

我希望能够将一些文本发送到看到here的确实应用小部件的输入字段。

如果您点击'立即申请'(很遗憾我无法将其链接),您会看到输入包含在2个iframe中。

有没有简单的方法可以访问它们? 这是我到目前为止所做的:

textbox = driver.find_element_by_id('applicant.name')

更新的代码(仍然无法与iframe交互)

from selenium import webdriver
driver = webdriver.Firefox()
driver.get('http://ca.indeed.com/cmp/Clearview-Plumbing-&-Heating/jobs/HVAC-Installer-Opening-6183dce44a9bfe10?sjdu=vQIlM60yK_PwYat7ToXhk42rccfWGklJDtD_zDpWBzDCfUEiSP2Zk-zLpFc6GNuF8wyV4_UaMyNFtpjETvX0fCpQXc3PxTbrGkwAMNkR5vGMtAfe9wNpTncItNgAIJHx' )
driver.find_element_by_class_name("indeed-apply-widget").click()
    # move into the iframe

iframe = driver.find_elements_by_tag_name('iframe')[0]
driver.switch_to_frame(iframe)

1 个答案:

答案 0 :(得分:0)

您想要的元素位于两个嵌套IFRAME内。以下代码应该有效。您需要进入第一帧...然后是第一个嵌套帧。其余的应该在那时工作。

driver = webdriver.Firefox()
driver.get('http://ca.indeed.com/cmp/Clearview-Plumbing-&-Heating/jobs/HVAC-Installer-Opening-6183dce44a9bfe10?sjdu=vQIlM60yK_PwYat7ToXhk42rccfWGklJDtD_zDpWBzDCfUEiSP2Zk-zLpFc6GNuF8wyV4_UaMyNFtpjETvX0fCpQXc3PxTbrGkwAMNkR5vGMtAfe9wNpTncItNgAIJHx')
driver.find_element_by_css_selector("span.indeed-apply-button-label")).click()
driver.switch_to_frame(0)
driver.switch_to_frame(0)
driver.find_element_by_id("applicant.name")).send_keys(username)
driver.find_element_by_id("applicant.email")).send_keys(email)
driver.find_element_by_id("resume")).send_keys(resumePath)
driver.find_element_by_css_selector("a.button_content.form-page-next")).click()
driver.find_element_by_id("apply")).click()