如何在Python中使用Selenium在https://in.indeed.com/网站内单击“继续"按钮? [英] How to click the Continue button within https://in.indeed.com/ website using selenium in python?

查看:72
本文介绍了如何在Python中使用Selenium在https://in.indeed.com/网站内单击“继续"按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个代码,该代码能够自动应用在true.com上的职位空缺上.我已经设法到达最后阶段,但是,最后单击申请表给我带来了很多麻烦.请参考以下页面

登录到我的个人资料后,我转到相关的搜索页面,单击我感兴趣的列表,然后在最后一页(如上所示)中尝试使用xpath单击继续按钮.对于上一步(也是同一表单上的页面),该表单具有多个iframe,我可以成功对其进行切换.现在,对于当前页面,我被卡住了,因为单击功能无法执行任何操作.我编写了以下代码:

  driver.get("https://in.indeed.com/jobs?q=data%20analyst&l=Delhi&vjk=5c0bd416675cf4e5")driver.find_element_by_xpath('//* [@ id ="apply-button-container"]/div [1]/span [1]').click()time.sleep(5)frame_1 = driver.find_element_by_css_selector('iframe [title ='Job application form container''))driver.switch_to.frame(frame_1)frame_2 = driver.find_element_by_css_selector('iframe [title ="Job application form"]')driver.switch_to.frame(frame_2)continue_btn = driver.find_element_by_css_selector('#form-action-continue')Continue_btn.click()driver.find_element_by_xpath('//* [@ id ="form-action-continue"]').click() 

我为此步骤尝试再次切换iframe,但没有任何反应.甚至.click()函数也不会执行任何操作.

在此方面将为您提供帮助.

解决方案

元素 Continue 位于嵌套的< iframe> 元素内,因此您必须:

  • 引发


    参考

    您可以在以下位置找到一些相关的讨论:

    I am trying to write a code that is able to auto apply on job openings on indeed.com. I have managed to reach the last stage, however, the final click on the application form is giving me a lot of trouble. Please refer the page as below

    Once logged in to my profile, I go to the relevant search page, click on the listing I am interested in and then on the final page (shown above) I am trying to click on the continue button using xpath. For the previous step (also a page on the same form), the form had multiple iframes which I was able to switch successfully. Now for the current page, I am stuck as the click function does not do anything. I have written the following code:

    driver.get("https://in.indeed.com/jobs?q=data%20analyst&l=Delhi&vjk=5c0bd416675cf4e5")
    driver.find_element_by_xpath('//*[@id="apply-button-container"]/div[1]/span[1]').click()
    time.sleep(5)
    frame_1 = driver.find_element_by_css_selector('iframe[title="Job application form container"')
    driver.switch_to.frame(frame_1)
    frame_2 = driver.find_element_by_css_selector('iframe[title="Job application form"]')
    driver.switch_to.frame(frame_2)
    continue_btn = driver.find_element_by_css_selector('#form-action-continue')
    continue_btn.click()
    driver.find_element_by_xpath('//*[@id="form-action-continue"]').click() 
    

    I have tried switching the iframes again for this step but nothing happens. Even the .click() function does not do anything.

    Will appreciate some help on this.

    解决方案

    The element Continue is within nested <iframe> elements so you have to:

    • Induce WebDriverWait for the parent frame to be available and switch to it.

    • Induce WebDriverWait for the child frame to be available and switch to it.

    • Induce WebDriverWait for the desired element to be clickable.

    • You can use either of the following Locator Strategies:

      • Using CSS_SELECTOR:

        driver.get("https://in.indeed.com/jobs?q=data%20analyst&l=Delhi&vjk=5c0bd416675cf4e5")
        WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span.indeed-apply-button-label"))).click()
        WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[id^='indeedapply-modal-preload']")))
        WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[title='Job application form']")))
        WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button#form-action-continue"))).click()
        

      • Using XPATH:

        driver.get("https://in.indeed.com/jobs?q=data%20analyst&l=Delhi&vjk=5c0bd416675cf4e5")
        WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[@class='indeed-apply-button-label']"))).click()
        WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[starts-with(@id, 'indeedapply-modal-preload')]")))
        WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@title='Job application form']")))
        WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@id='form-action-continue']"))).click()
        

    • Note : You have to add the following imports :

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

    • Browser Snapshot:


    Reference

    You can find a couple of relevant discussions in:

    这篇关于如何在Python中使用Selenium在https://in.indeed.com/网站内单击“继续"按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆