1

Is it because i using python REPL? I don't know what that is.

full code and error image

My code:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)

driver.get("https://member.lazada.com.my/user/login?spm=a2o4k.home.header.d5.1e532e7eD9UgkJ&redirect=https%3A%2F%2Fwww.lazada.com.my%2F%3Fspm%3Da2o4k.login_signup.header.dhome.7d0d49fbWgHyQw")
print(driver.title)

time.sleep(10)

driver.find_element_by_id("a2o4k.login_signup.menu.i0.128549fbdpzNIi").click()

Error code:

Lazada.com.my: Online Shopping Malaysia - Mobiles, Tablets, Home Appliances, TV, Audio & More
Traceback (most recent call last):
  File "C:\Program Files (x86)\CUBAR.py", line 13, in <module>
    driver.find_element_by_id("a2o4k.login_signup.menu.i0.128549fbdpzNIi").click()
  File "C:\Users\naufa\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 360, in find_element_by_id
    return self.find_element(by=By.ID, value=id_)
  File "C:\Users\naufa\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 976, in find_element
    return self.execute(Command.FIND_ELEMENT, {
  File "C:\Users\naufa\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\naufa\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="a2o4k.login_signup.menu.i0.128549fbdpzNIi"]"}
  (Session info: chrome=87.0.4280.66)
cizario
  • 3,995
  • 3
  • 13
  • 27
  • Can you [edit] this post to properly format your code, and error messages? It would also be helpful if you provided an explanation of what you expected your code to do as well as what actually happens when you run it. – sphennings Nov 27 '20 at 06:20

1 Answers1

1

You're trying to find an id that is dynamic and will change instead use either a css selector or xpath. I am assuming you are trying to click the sign up button or something similar. Here's an example of that element.

CSS SELECTORS

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.mod-login-btn > button"))).click()

XPATHS

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "button[text()='SIGN UP']"))).click()

Import

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC
Arundeep Chohan
  • 9,779
  • 5
  • 15
  • 32