1

I am having trouble using selenium and using CSS select for onclick.

The HTML code looks like this:

<div class="hexagon pointer" onclick="login.LoginCACSynchro('SYNCHRO');">

My current code looks like this:

Synchro = driver.find_element_by_css_selector("a[onclick^='login.LoginCACSynchro('SYNCHRO');']")

Not sure what I a doing wrong here, any help would be very appreciated!


Update

It looks like it wants to work but I am getting this error:

Message: element click intercepted: Element <div class="hexagon pointer" onclick="login.LoginCACSynchro('SYNCHRO');">...</div> is not clickable at point (651, 543). Other element would receive the click: <div id="loader2" style="opacity: 0.627993;">...</div> (Session info: chrome=103.0.5060.134)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Abwethin85
  • 25
  • 4
  • Did you try to scroll the page to that element, to make sure it's in view? You can do it by executing Javascript, with `browser.execute_script('...')`. First scroll to that element, then click on it. – Barry the Platipus Jul 22 '22 at 13:22

1 Answers1

0

To click on the element you can use either of the following locator strategies:

  • Using css_selector:

    driver.find_element(By.CSS_SELECTOR, "div.hexagon.pointer[onclick^='login'][onclick*='LoginCACSynchro'][onclick*='SYNCHRO']").click()
    
  • Using xpath:

    driver.find_element(By.XPATH, "//div[@class='hexagon pointer' and starts-with(@onclick, 'login')][contains(@onclick, 'LoginCACSynchro') and contains(@onclick, 'SYNCHRO')]").click()
    

Update

As per your comment update to click on the element:

  • First induce WebDriverWait for the invisibility_of_element

  • Then induce WebDriverWait for the element_to_be_clickable() as follows:

    • Using CSS_SELECTOR:

      WebDriverWait(driver, 30).until(EC.invisibility_of_element((By.CSS_SELECTOR, "div#loader2")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.hexagon.pointer[onclick^='login'][onclick*='LoginCACSynchro'][onclick*='SYNCHRO']"))).click()
      
    • Using XPATH:

      WebDriverWait(driver, 30).until(EC.invisibility_of_element((By.XPATH, "//div[@id='loader2']"))) 
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='hexagon pointer' and starts-with(@onclick, 'login')][contains(@onclick, 'LoginCACSynchro') and contains(@onclick, 'SYNCHRO')]"))).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
  • Hey both did not work, getting error message Message: no such element: Unable to locate element: {"method":"xpath","selector":"//a[@class='hexagon pointer' and contains(@onclick, 'LoginCACSynchro')]"} – Abwethin85 Jul 22 '22 at 11:30
  • This is the whole HTML code
    – Abwethin85 Jul 22 '22 at 11:31
  • It looks like it wants to work but I am getting this error: Message: element click intercepted: Element
    ...
    is not clickable at point (651, 543). Other element would receive the click:
    ...
    (Session info: chrome=103.0.5060.134)
    – Abwethin85 Jul 22 '22 at 11:39
  • Maybe this button is unclickable? Using the python script provided and the imports and still getting the same error not clickable point. – Abwethin85 Jul 22 '22 at 11:45
  • Is it possible I can screen share and see if what I a telling you could be off? If we find the answer I can check mark it on here. – Abwethin85 Jul 22 '22 at 11:57
  • Let's discuss the issue in [Selenium](https://chat.stackoverflow.com/rooms/223360/selenium) room. – undetected Selenium Jul 22 '22 at 12:02
  • The room says this : You must have 20 reputation on Stack Overflow to talk here. See the faq. – Abwethin85 Jul 22 '22 at 12:09
  • Gimme a moment, I guess I nailed the issue. – undetected Selenium Jul 22 '22 at 12:13
  • I used both, I am still getting the same error with the ID = Loader 2 – Abwethin85 Jul 22 '22 at 12:27
  • That was bad, typo, corrected the error. Checkout the updated answer and let me know the status. – undetected Selenium Jul 22 '22 at 12:30
  • Unfortunately both did not work, getting the exact same error with the ID = Loader2. – Abwethin85 Jul 22 '22 at 12:37
  • Seems now you are messing up, your earlier comment `
    ...
    ` (lower l) but now you mentioned `ID = Loader2` (upper L)
    – undetected Selenium Jul 22 '22 at 12:39
  • No doubt it could be me the the error I am seeing is the sameMessage: element click intercepted: Element
    ...
    is not clickable at point (651, 543). Other element would receive the click:
    ...
    (Session info: chrome=103.0.5060.134)
    – Abwethin85 Jul 22 '22 at 12:41
  • Any chance there is a possible screen share so you can see exactly what is going on? Again I appreciate your time and the help! – Abwethin85 Jul 22 '22 at 13:03
  • Of coarse there are. Look around – undetected Selenium Jul 22 '22 at 13:05
  • I meant specifically if you could help, and the screen share. I promise it will not take long. – Abwethin85 Jul 22 '22 at 13:07
  • I have tried, and looked around been working on this for a while now and you have gotten me along the farthest. Sorry for the persistence, this button is the first button that needs to be clicked on the page. I still have more to do after this. – Abwethin85 Jul 22 '22 at 13:20
  • Hey there, if I add time.sleep(10) before the WebDriverWait it works. There is a Agreement banner that pops up, once you hit agree with the added time.sleep() the code recongnizes the button. Any way around the agreement banner popup? – Abwethin85 Jul 22 '22 at 17:40
  • From your comment `
    ` indicated a loader which I have taken care of through `invisibility_of_element()` but had no idea of the **Agreement banner**. Glad to help you out.
    – undetected Selenium Jul 22 '22 at 20:44
  • Ahh got ya, the site is unique the agreement banner shows up then after that the page loads. There is a huge loading icon that slowly fades away to the screen where the link needs to be clicked. Again thanks for the help! – Abwethin85 Jul 24 '22 at 19:24