John DeBritto
John DeBritto

Reputation: 141

How to click on the element on a webpage as per the HTML using selenium and Python

I have been trying for a while now but can't seem to find this element using python selenium. All methods I used whether they were find with xpath, css selector, and or class came back negative so does anybody know how to find and click the element in the middle that has the value "LOG IN" and the type "button"?

<div id="62b00cbb-fb56-4b15-80bb-a8f965d02d90" class="nike-unite-submit-button loginSubmit nike-unite-component blurred">
 <input id="019a8673-60aa-4b9f-825a-00b01ad36507" type="button" value="LOG IN"> # Click This
</div>

I just can't seem to find it so any and all help is appreciated, thanks!

firefox_options = webdriver.FirefoxOptions()
driver = webdriver.Firefox(firefox_options=firefox_options)
driver.get('https://www.nike.com/launch/?cp=usns_aff_nike&s=upcoming')
time.sleep(.2)
logIn = driver.find_element_by_css_selector('#root > div > div > div.main-       layout > div > header > div.d-sm-h.d-lg-b > section > ul > li.member-nav-item.d-sm-ib.va-sm-m > button')
logIn.click()
time.sleep(.2)
email = driver.find_element_by_name('emailAddress')
email.send_keys('email')
passWord = driver.find_element_by_name('password')
passWord.send_keys('password')

# Find and click element from above

Everything else works fine its just when it comes to the select login button. Here is the code just in case their could be something wrong with it or somebody wanted to check it out, thanks

Upvotes: 1

Views: 221

Answers (2)

undetected Selenium
undetected Selenium

Reputation: 193058

To invoke click() on the element with text as LOG IN you need to induce WebDriverWait for the element to be clickable and you can use either of the following solutions:

  • css_selector:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.nike-unite-submit-button.loginSubmit.nike-unite-component.blurred > input[value='LOG IN']"))).click()
    
  • xpath:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='nike-unite-submit-button loginSubmit nike-unite-component blurred']/input[@value='LOG IN']"))).click()
    

Upvotes: 1

Shashank Verma
Shashank Verma

Reputation: 377

You can find the button by using the ID of the button and then click it:

button = driver.find_element_by_id('019a8673-60aa-4b9f-825a-00b01ad36507')
button.click()

Here, driver is your browser webdriver.

Upvotes: 0

Related Questions