1

I've been trying to figure out how to wait for an element to be loaded and then execute the click function in python.

The website I am talking about is: https://tempail.com/

As soon as I received an e-mail, I want the script to click on it and then execute further tasks.

I tried to solve this problem through the "Try/Except Function", but I always receive error messages.

Source of the site: https://i.stack.imgur.com/n2z6E.png

The problem is that the site uses generated IDs I can't use in the find_element_by function.

This is what I've tried so far: https://i.stack.imgur.com/LlN6f.png

With try, I wanted the script to wait until the site received the mail. As soon as the mail is in the inbox, it should click the link/the mail and open it.

Apart from that, I looked up for more solutions, but nothing really helped out, but with this code I always receive the following error:

Message: no such element: Unable to locate element: {"method":"css selector","selector":".epostalar ul li.mail a"}

Plus it doesn't even wait for the mail.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Keanu
  • 211
  • 1
  • 4
  • 12

1 Answers1

1

As soon as you receive an e-mail, to invoke click() on it you have to induce WebDriverWait for the element to be clickable and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "ul.mailler li.mail a"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//ul[@class='mailler']//li[contains(@class, 'mail')]//a"))).click()
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352