[英]How to click the Continue button on website using selenium in python?
I am trying to write a code that is able to auto apply on job openings on indeed.com.我正在尝试编写一个能够自动申请确实.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
as follows:登录到我的个人资料后,我将 go 转到相关搜索页面,单击我感兴趣的列表,然后在最后一页(如上所示)我尝试使用
xpath
单击continue
按钮,如下所示:
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()
driver.find_element_by_xpath('//*[@id="form-action-continue"]')
However, this gives me an error:但是,这给了我一个错误:
Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="form-action-continue"]"}
Having gone through some suggestions on the net I have even tried the following:在网上浏览了一些建议后,我什至尝试了以下方法:
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()
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="form-action-continue"]')))
But then this gives me a timeout error但这给了我一个超时错误
TimeoutException: Message:
Will appreciate some help on this.将不胜感激这方面的一些帮助。
From it seems, on that form there are multiple iframe
s, therefore the reason for your errors.看来,在该表格上有多个
iframe
,因此是您错误的原因。
You need to get the first iframe
, switch to it, get the second iframe
inside the first one, switch to it and only afterwards you'll be able to get the continue
button.您需要获得第一个
iframe
,切换到它,在第一个中获得第二个iframe
,切换到它,然后您才能获得continue
按钮。
Something like this should do the trick:这样的事情应该可以解决问题:
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()
Once I had a similar issue and standard time.sleep() until the form (or continue button) appears helped me.一旦我遇到类似的问题和标准 time.sleep() 直到出现表单(或继续按钮)对我有帮助。 Try it instead of WebDriverWait, maybe it will work.
试试它而不是 WebDriverWait,也许它会起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.