0

Im trying to click on a div tag. I've been trying different combinations of locators for the past several hours and can't for the life of me figure out how to fix it. It is not in an iframe.

Here is the line of python code:

WebDriverWait(browser,20).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"#mail > div > div.view-columns.backface_fix.flex-grow.rel > div:nth-child(1) > div > div > div > div.rel.flex-grow > div > ul > li:nth-child(1) > div > div.flex-grow.min-width-0 > div.bottom.flex-space-between > div"))).click()

this is the html:

<div class="text-ellipsis flex-grow">Proton Verification Code</div>
Prophet
  • 32,350
  • 22
  • 54
  • 79
  • Coconutwater's answer should work but if does not share the url with us, will check – Himanshu Poddar Aug 18 '22 at 06:08
  • Did you check your locator in the browser? Open the page in Chrome, press F12 to open the devtools, press ESC to see the console, and type `$$("#mail > div > div.view-columns.backface_fix.flex-grow.rel > div:nth-child(1) > div > div > div > div.rel.flex-grow > div > ul > li:nth-child(1) > div > div.flex-grow.min-width-0 > div.bottom.flex-space-between > div")`, and press ENTER. Does it return anything? I'm guessing not. That's a pretty long/complex locator and likely the issue. If you link the page, we can probably find a better locator that will work. – JeffC Aug 19 '22 at 19:02

3 Answers3

1

You did not provided enough information in your post so we can't give you a 100% correct solution, however maybe this will work for you:

WebDriverWait(browser,20).until(EC.element_to_be_clickable((By.XPATH,"//div[contains(text(),'Proton Verification Code')]"))).click()

Prophet
  • 32,350
  • 22
  • 54
  • 79
0

Given the HTML:

<div class="text-ellipsis flex-grow">Proton Verification Code</div>

To click on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use the following locator strategy:

  • Using XPATH:

    WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='text-ellipsis flex-grow' and text()='Proton Verification Code']"))).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
-1

You can try "By.XPATH" instand of "By.CSS_SELECTOR":

WebDriverWait(browser,20).until(EC.element_to_be_clickable((By.XPATH,"//div[@class='text-ellipsis flex-grow']"))).click()