1

I'm trying to get text of an element in the temp mail website which is;

https://www.temporary-mail.net/

My purpose is to get temp mail as a string

the CSS : "input#active-mail" XPATH = "//*[@id="active-mail"]"

i tried to use .text and get_attribute() methods, but failed!

I could not get the text of the CSS element, am i doing something wrong? As far as I can see it is not in the iFrame but I'm not sure, can someone enlighten me ?

codes:

    driver.get("https://www.temporary-mail.net/")
    kontrol = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.XPATH, '//*[@id="active-mail"]'))
    )
    time.sleep(1)
    tmpMail_text = driver.find_element_by_xpath('//*[@id="active-mail"]').text
    #or
    tmpMail_attr = driver.find_element_by_xpath('//*[@id="active-mail"]').get_attribute("data-clipboard-text")
    print(tmpMail_text )
    print(tmpMail_attr )
    time.sleep(1)
Fatih Tüz
  • 133
  • 1
  • 12

1 Answers1

2

To print the value of the temporary -mail e.g. 68p7wixe@temporary-mail.net you need to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies:

  • Using XPATH:

    driver.get('https://www.temporary-mail.net/')
    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "input#active-mail"))).get_attribute("data-clipboard-text"))
    
  • Using CSS_SELECTOR:

    driver.get('https://www.temporary-mail.net/')
    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//input[@id='active-mail']"))).get_attribute("data-clipboard-text"))
    
  • Console Output:

    68p7wixe@temporary-mail.net
    
  • 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
    

Update

As an alternative instead of visibility_of_element_located() you can also try element_to_be_clickable() as follows:

  • Using CSS_SELECTOR:

    print(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='active-mail']"))).get_attribute("data-clipboard-text"))
    
  • Using XPATH:

    print(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='active-mail']"))).get_attribute("data-clipboard-text"))
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • firstly thx for your answer, i updated my question as real code snippet. I already tried your solution but, it didnt work. Did you try and achieve with these methods coz I dont :( – Fatih Tüz Sep 12 '20 at 21:41
  • 2
    @FatihTüz Generally, I don't publish answers with untested lines of code. – undetected Selenium Sep 12 '20 at 21:44
  • I didnt want to be rude, sorry i you understand me in a wrong way. I again tried just your code with neccesary imports. C:\Users\MFT\PycharmProjects\investing\venv\Scripts\python.exe C:/Users/MFT/PycharmProjects/investing/deneme.py Process finished with exit code 0 this is the output. I'm using chromedriver 85. Could there be any other problem? – Fatih Tüz Sep 12 '20 at 21:46
  • @FatihTüz Checkout the updated answer and let me know the status. – undetected Selenium Sep 12 '20 at 21:50
  • It solved, great! I have one more question, why did you change your idea as an element to be clickable? If i have this or any other situation again, how can I decide to make these changes? I mean is there any clue for element_to_be_clickable – Fatih Tüz Sep 12 '20 at 21:52
  • 1
    @FatihTüz Honestly I admire your question because very less programmers try to get whats happening under the hood. The logic is `visibility_of_element_located` refers to `width` and `height` greater then `0` but `element to be clickable` refers to the interactive state. As the element is an `` element incase `visibility_of_element_located` failed we can always fall back on `element to be clickable` clause. Checkout the [WebDriverWait](https://stackoverflow.com/questions/52603847/how-to-sleep-webdriver-in-python-for-milliseconds/52607451#52607451) link. – undetected Selenium Sep 12 '20 at 21:59
  • 1
    Thanks for all your help! and your thought. Now I got the idea :) – Fatih Tüz Sep 12 '20 at 22:05