-2

I am trying to automate the download of information from the company web-portals. I need to specify a custom date range (in other parts of the code).

The page html is in the following format

<div id="datePickerIconWrap" class="float_lang_base_2 datePickerIconWrap"><span class="datePickerIcon">&nbsp;</span></div>

I have tried specifying the item by either class_name and id; but both fails

import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
url = '<my url>'

driver = webdriver.Chrome("Y:/Users/admin/Documents/chromedriver.exe")
driver.get(url)
driver.find_element_by_id('datePickerIconWrap').click()    
driver.find_element_by_class_name('float_lang_base_2 datePickerIconWrap').click()

I get the error message below for .find_element_by_id

ElementNotVisibleException: Message: element not visible

I get the error message below for .find_element_by_class

InvalidSelectorException: Message: invalid selector: Compound class names not permitted
(Session info: chrome=68.0.3440.106)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Kiann
  • 531
  • 1
  • 6
  • 20

1 Answers1

0

About the errors:

  • This error message ElementNotVisibleException: Message: element not visible implies that the desired element was not visible within the HTML DOM.
  • This error message InvalidSelectorException: Message: invalid selector: Compound class names not permitted implies that the Locator Strategy you have adapted was not a valid one.

Solution

To invoke click() on the desired element you can use either of the following solution:

  • CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.float_lang_base_2.datePickerIconWrap>span.datePickerIcon"))).click()
    
  • XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='float_lang_base_2 datePickerIconWrap']/span[@class='datePickerIcon']"))).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