0

I am trying to create a scraper for Etsy shop managers but after I log in I am unable to use the code to locate the shop manager button(NoSuchElement). Here is my code:

from selenium import webdriver


options = webdriver.ChromeOptions()
options.add_argument('--incognito')

driverLocation = 'Downloads/chromedriver'

driver = webdriver.Chrome(driverLocation)

driver.get("https://www.etsy.com/signin")
username = driver.find_element_by_id("join_neu_email_field")
username.clear()
username.send_keys("username")

password = driver.find_element_by_id("join_neu_password_field")
password.clear()
password.send_keys("password")

driver.find_element_by_name("submit_attempt").click()

driver.implicitly_wait(10)

driver.find_element_by_class_name("wt-display-inline-flex-xs wt-flex-direction-column-xs wt-align-items-center wt-text-link-no-underline wt-p-xs-2 wt-pt-lg-0 wt-pb-lg-0 wt-pl-lg-1 wt-pr-lg-1 ge-nav-link reduced-margin-xs").click()

driver.quit()

The button I am trying to locate on the website:

The button I am trying to locate on the website

I've tried various different methods(xpath, class_name, css_selector). I only see the class name as an identifier so I am not sure why its not working.

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

3 Answers3

0
     driver.find_element_by_class_name("wt-display-inline-flex-xs.wt-flex-direction-column-xs.wt-align-items-center.wt-text-link-no-underline.wt-p-xs-2.wt-pt-lg-0.wt-pb-lg-0.wt-pl-lg-1.wt-pr-lg-1.ge-nav-link.reduced-margin-xs").click()

Space in class shows that it's multiple classes you have to replace space with dot

Else use xpath or css

   driver.find_element_by_xpath("//*[@class=\"wt-display-inline-flex-xs wt-flex-direction-column-xs wt-align-items-center wt-text-link-no-underline wt-p-xs-2 wt-pt-lg-0 wt-pb-lg-0 wt-pl-lg-1 wt-pr-lg-1 ge-nav-link reduced-margin-xs\"]").click()



   driver.find_element_by_cssSelector("[class=\"wt-display-inline-flex-xs wt-flex-direction-column-xs wt-align-items-center wt-text-link-no-underline wt-p-xs-2 wt-pt-lg-0 wt-pb-lg-0 wt-pl-lg-1 wt-pr-lg-1 ge-nav-link reduced-margin-xs\"]").click()

This will select element that has attribute class with exact value

PDHide
  • 18,113
  • 2
  • 31
  • 46
0

The <a> element have a child <span>. So to click on the element you can use either of the following Locator Strategies:

  • Using css_selector:

    driver.find_element_by_css_selector("a[href^='https://www.etsy.com/your/shops/me/dashboard'] > span").click()
    
  • Using xpath:

    driver.find_element_by_xpath("//button[@class='save' and text()='save']").click()
    

Ideally, to click on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[href^='https://www.etsy.com/your/shops/me/dashboard'] > span"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[starts-with(@href, 'https://www.etsy.com/your/shops/me/dashboard')]/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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

You should not use class name here because this class looks pretty much dynamic. Using href attribute value in xpath is also not suggested.

  1. In this case you should write an xpath with respect to some element which has static attribute or text. I feel there is a text in span tag so here you can try - //span[text()='putTheTextValue']/parent::a

  2. Put a 5sec wait before interacting to this element just to make sure it is loaded when you are looking for this element. Later you can adjust this.