0

I'm attempting to login to a website using selenium and python. I'm using PyCharm for the IDE. I've found the class name for the login button, but when I search for and try to click it using:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time

notsure=Service(r"C:\Users\kumpd\OneDrive\Desktop\Project\chromedriver_win32\chromedriver.exe")
website = "https://buff.market/market/goods/1?game=csgo"

path = r"C:\Users\kumpd\OneDrive\Desktop\Project\chromedriver_win32\chromedriver.exe"

driver = webdriver.Chrome(service=notsure)

driver.get(website)

time.sleep(10)

login = driver.find_element(By.CLASS_NAME, "w-button c-nav-sign w-button--primary w-button--l")
login.click()

driver.quit()

Here is the HTML from the website: enter image description here

I get the following error:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".w-button c-nav-sign w-button--primary w-button--l"}
Backtrace:
    (No symbol) [0x0026DCE3]
    (No symbol) [0x002039D1]
    (No symbol) [0x00114DA8]
    (No symbol) [0x0014019F]
    (No symbol) [0x001403AB]
    (No symbol) [0x0016EE62]
    (No symbol) [0x0015AF14]
    (No symbol) [0x0016D57C]
    (No symbol) [0x0015ACC6]
    (No symbol) [0x00136F68]
    (No symbol) [0x001380CD]
    GetHandleVerifier [0x004E3832+2506274]
    GetHandleVerifier [0x00519794+2727300]
    GetHandleVerifier [0x0051E36C+2746716]
    GetHandleVerifier [0x00316690+617600]
    (No symbol) [0x0020C712]
    (No symbol) [0x00211FF8]
    (No symbol) [0x002120DB]
    (No symbol) [0x0021C63B]
    BaseThreadInitThunk [0x76AE7D69+25]
    RtlInitializeExceptionChain [0x77B0BB9B+107]
    RtlClearBits [0x77B0BB1F+191]
    (No symbol) [0x00000000]

Any idea why selenium can't find the button? Thanks for the help!

As you can see I did already try using time sleep to force the webpage to wait.

  • Try ```login = driver.find_element(By.CSS_SELECTOR, "button#my-button.w-button.c-nav-sign.w-button--primary.w-button--1")``` . This should work. – Harish Mar 16 '23 at 16:55
  • I get the same error as before. – Dallin Kump Mar 16 '23 at 17:27
  • ```login = driver.find_element(By.CSS_SELECTOR, "button#my-button.w-button.c-nav-sign.w-button--primary.w-button--l")``` Try this. There was a typo in my earlier comment , had used '1' instead of 'l' . – Harish Mar 17 '23 at 04:34

3 Answers3

0

try this code

 driver.find_element_by_class_name("w-button.c-nav-sign.w-button--primary.w-button--l")

if you keep getting that error try this code

driver.find_element_by_xpath("//*[text()='write text on button']").click()
0

To click on the element Sign in insteadog targetting the <button> tag you can move one step deeper and target the <span> tag and inducing WebDriverWait for the element_to_be_clickable() you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    driver.get("https://buff.market/market/goods/1?game=csgo")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.w-button.c-nav-sign.w-button--primary.w-button--l > span"))).click()
    
  • Using XPATH:

    driver.get("https://buff.market/market/goods/1?game=csgo")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='w-button c-nav-sign w-button--primary w-button--l']/span"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
  • Browser Snapshot:

buff_market

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
-2

I have ran into an error similar to this in the past. Most of the time it has to do with the Chrome driver version. ensure that you install the chrome driver version that matches the version of you chrome browser. Chrome Browser Version

Chrome Driver Version

My chrome browser likes to update on its own and then I have to update the Chrome driver again, that usually when I get an error that looks just like this. might not fix the problem but may help

Joe Hick
  • 7
  • 2