Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Element not interactable selenium [duplicate]

I'm trying to check out on the nike webstore but I have tried everything and searched and can't find an answer to it.

https://www.nike.com/nl/nl/checkout/tunnel

I have:

driver.find_element_by_xpath('//button[@id="qa-guest-checkout-mobile"]').click()

<button id="qa-guest-checkout-mobile" aria-label="Guest Checkout" 
class="ncss-btn-accent u-rounded u-full-width ncss-brand u-uppercase pt3-sm pt2-lg pr5-sm pb3-sm pb2-lg pl5-sm fs14-sm d-lg-h">
<span class="d-sm-ib va-sm-m mr1-sm">Afrekenen als bezoeker</span></button>

I have tried to use find by id, css and more, but it isn't working. What am I doing wrong here? When I print the elements I only get 1 element and I dont get an error then.

  File "C:\Users\X\OneDrive\Desktop\SN\NA.py", line 23, in <module>
    test = driver.find_element_by_xpath('//button[@id="qa-guest-checkout-mobile"]').click()
  File "C:\Users\X\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
    self._execute(Command.CLICK_ELEMENT)
  File "C:\Users\X\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "C:\Users\X\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\X\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: element not interactable
  (Session info: chrome=74.0.3729.131)
  (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Windows NT 10.0.17134 x86_64)
like image 307
Number70 Avatar asked May 13 '19 20:05

Number70


1 Answers

After a good amount of searching I found this post with this answer and was able to make this code:

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

browser = webdriver.Chrome()
browser.get('https://www.nike.com/nl/nl/checkout/tunnel')
element = WebDriverWait(browser, 20).until(EC.presence_of_element_located((By.XPATH, "//div/button[@id='qa-guest-checkout-mobile']")))
browser.execute_script("arguments[0].click();", element)

Which successfully clicks on the button. For some reason you have to force click the button using javascript...

like image 60
Reedinationer Avatar answered Sep 28 '22 02:09

Reedinationer