0

I got a BUTTON variable for those buttons:

GoMailsBTN = browser.find_element_by_class_name("D(ib) Fz(14px) Fw(b) Lh(24px) Pstart(38px)")
GoMailsBTN.click()

and there is not like any id you can go check it out by yourself if you want! This is the error that pops out selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: An invalid or illegal selector was specified Anyone got any idea why this is?

Snapshot of the button:

html

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
CatGuy
  • 11
  • 2
  • Post the HTML of the button in your answer so we can create a locator. ... and the problem is that the string you are passing is not a valid class name. There are no spaces in a valid class name... and probably not parentheses. – JeffC Jul 04 '20 at 21:05

2 Answers2

0

The class name is dynamic and can change, in this case, you can use xpath:

browser.find_element_by_xpath("//li//a[contains(@href ,'mail') and not(@id)]")
Norayr Sargsyan
  • 1,737
  • 1
  • 12
  • 26
0

The desired element is a JavaScript enabled element so to click on the element you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    driver.get('https://in.yahoo.com/?p=us')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a#header-mail-button span"))).click()
    
  • Using XPATH:

    driver.get('https://in.yahoo.com/?p=us')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@id='header-mail-button']//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:

yahoomail

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