我正在尝试访问确实工作申请平台上的立即申请按钮。当我单击它时,它会跳到一个新的框架中,我想在其中访问元素。我已经在其他网页上测试了该代码,并且可以成功访问iframe的元素,但是在此特定页面上出现错误。
代码如下:
from selenium import webdriver
driver = webdriver.Firefox(executable_path = 'C:\\Users\\Sonorityscape\\Desktop\\geckodriver.exe')
driver.get('https://www.indeed.com/jobs?q=Game%20Audio&start=10&vjk=836d4ff796e19392#')
iframes = driver.find_elements_by_tag_name("iframe")
iframes
[<selenium.webdriver.firefox.webelement.FirefoxWebElement (session="fdfc346e-535b-45ea-b127-fe5d386fd6b7", element="d699e195-e4f5-4430-9851-9d98a0af925d")>]
driver.switch_to.frame(iframes[0])
driver.find_element_by_css_selector('#input-applicant\.firstName')
这是错误:
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
driver.find_element_by_css_selector('#input-applicant\.firstName')
File "C:\Users\Sonorityscape\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 597, in find_element_by_css_selector
return self.find_element(by=By.CSS_SELECTOR, value=css_selector)
File "C:\Users\Sonorityscape\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 966, in find_element
'value': value})['value']
File "C:\Users\Sonorityscape\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute
self.error_handler.check_response(response)
File "C:\Users\Sonorityscape\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: #input-applicant\.firstName
这里是页面的链接:
https://www.indeed.com/jobs?q=Game%20Audio&start=10&vjk=836d4ff796e19392#
答案 0 :(得分:0)
根据您的代码,您没有单击立即应用按钮,而是在单击框架后将其加载,并在第二个iframe中加载。以下代码可能会对您有所帮助。
from selenium import webdriver
driver = webdriver.Firefox(executable_path = 'C:\\Users\\Sonorityscape\\Desktop\\geckodriver.exe')
driver.get('https://www.indeed.com/jobs?q=Game%20Audio&start=10&vjk=836d4ff796e19392#')
driver.find_element_by_css_selector('span.indeed-apply-button-label').click() #click on apply now button
iframes = driver.find_elements_by_tag_name("iframe")
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it(frames[1])
driver.find_element_by_css_selector('#input-applicant\.firstName').send_keys("firstname")