1

I am using Python Selenium to open https://www.walmart.com/ and then want to click "Create an account" tab under "Sign In Account" as shown in this Walmart website pic. The source code of button from Walmart website along with the image is as follows:

<a link-identifier="Create an account" class="no-underline" href="/account/signup?vid=oaoh">
<button class="w_C8 w_DB w_DE db mb3 w-100" type="button" tabindex="-1">Create an account</button>
</a>

Walmart Website Source code-Pic

My python code for opening https://www.walmart.com/ for accessing Create an account button and click on it is as follows:

import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

url = "https://www.walmart.com/"

s=Service('C:/Users/Samiullah/.wdm/drivers/chromedriver/win32/96.0.4664.45/chromedriver.exe')
driver = webdriver.Chrome(service=s)
driver.get(url)
driver.maximize_window()

elems = driver.find_element(By.XPATH, '//button[normalize-space()="Create an account"]')
time.sleep(3)
elems.click()

However I am getting this error of ElementNotInteractableException as shown by this Error Pic.

Can anyone guide me what is wrong with my code/approach?.

Thanks in advance

Prophet
  • 32,350
  • 22
  • 54
  • 79
salman dinani
  • 47
  • 1
  • 5

1 Answers1

0

You can not click this element directly, you have to hover over "Sign In" element to make this element appeared.
It is also highly recommended to use expected conditions.
This should work:

import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
url = "https://www.walmart.com/"

s=Service('C:/Users/Samiullah/.wdm/drivers/chromedriver/win32/96.0.4664.45/chromedriver.exe')
driver = webdriver.Chrome(service=s)
wait = WebDriverWait(driver, 20)
actions = ActionChains(driver)
driver.get(url)
driver.maximize_window()
sign_in_btn = wait.until(EC.visibility_of_element_located((By.XPATH, "//div[text()='Sign In']")))
actions.move_to_element(sign_in_btn).perform()
time.sleep(0.5)
wait.until(EC.visibility_of_element_located((By.XPATH, '//button[normalize-space()="Create an account"]'))).click()
Prophet
  • 32,350
  • 22
  • 54
  • 79