简体   繁体   中英

Selenium not identifying any element in particular HTML, why?

I have a list of URLs that I need to iterate over. The process I am working on is that selenium opens each of the URLs in the list, clicks a button to open the form, and pass some strings into the form.

I have gotten to the point of clicking the button to open the form. I can not pass in any strings into the form however using any of the elements. I get error 'Unable to locate element'

This is my code so far, easily_apply is list of the URLs:

for i in easily_apply:
    driver.get(i)
    test = driver.find_element_by_class_name('button')
    test.click()
    test.find_element_by_name("applicant.name")
    test.send_keys("John Smith")

This is the HTML in question:

<input type="text" aria-describedby="label-input-applicant.name-error" aria-labelledby="label-input-applicant.name" id="input-applicant.name" name="applicant.name" class="icl-TextInput-control icl-TextInput-control--sm">

Thank you in advance.

edit:

Code with xpath, not working, getting error 'Unable to locate elements':

for i in easily_apply:
    driver.get(i)
    test = driver.find_element_by_class_name('indeed-apply-button')
    test.click()
    test.find_element_by_xpath('//input[@type="text"]')
    test.send_keys("John Smith")

edit2:

code with wait in it, still getting same error 'Unable to locate elements':

for i in easily_apply:
    driver.get(i)
    test = driver.find_element_by_class_name('indeed-apply-button')
    test.click()
    wait = ui.WebDriverWait(driver,60)
    test.find_element_by_name('applicant.name')
    test.send_keys("John Smith")

I looked at the html, assuming you are using the code from your previous post, obtaining all the easily apply list.

The element you are looking for is inside nested iframe. you need to switch to that iframe and then look for the element

Replace the time.sleep with Webdriverwait

driver.find_element_by_css_selector('a[class="indeed-apply-button"]').click()
driver.switch_to.frame(driver.find_element_by_css_selector('iframe[name*=indeed-ia]'))

import time
time.sleep(5)

driver.switch_to.frame(driver.find_element_by_tag_name('iframe'))
driver.find_element_by_id('input-applicant.name').send_keys('Applicant Name')

Try using xpath.

In Selenium automation, if the elements are not found by the general locators like id, class, name, etc. then XPath is used to find an element on the web page .

Syntax is: Xpath=//tagname[@attribute='value']

Hope this helps.

 driver.find_element_by_css_selector("#jl_1c27f21fec51d296 > a").click() time.sleep(10) driver.find_element_by_css_selector('a[class="indeed-apply-button"]').click() 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM