0

The HTML:

enter image description here

My goal:

what I am trying to achieve right now is to find this textarea and use send.keys(). (for sending email (gmail) automation)

My problem:

Unable to locate this textarea.

Attempts to solve the problem:

I tried using id, but this does work because the id value seems to be constantly changing every time when I reload.

browser.find_element_by_id() 

Tried using class name, but this does not work either, no idea why.

browser.find_element_by_class_name("Ak aXjCH")

Tried to create time delay, have no effect on the outcomes

time.sleep(10)

Tried using to find the element using xpath, but i think i wrote the code incorrectly.

browser.find_element_by_xpath("//div[@class='Ar As']//div[@class='At']//textarea[@class='Ak aXjCH']")

New to selenium and coding I general. Thanks in advance.

CountDOOKU
  • 289
  • 3
  • 14

2 Answers2

1

How about this:

parentElement = browser.find_element_by_class_name("At")
elementList = parentElement.find_elements_by_tag_name("textarea")
0

I had this problem when I tried to login to Gmail and send an email remotely using Selenium. I noticed that the id's of the recipient field, subject field, email body field and send element changed each time I opened Gmail using Selenium (there were 2 different id's for each). I solved this problem by checking for each id as follows:

# click compose 
# when page is loaded, elements appear at different time intervals (AJAX)... 
# some elements may take some time to appear in the DOM
composeElem = WebDriverWait(browser, 5).until(EC.element_to_be_clickable((By.ID, ":3w")))
composeElem.click()

# add recipient
try: 
    recipientElem = WebDriverWait(browser, 5).until(EC.element_to_be_clickable((By.ID, ":96")))
except Exception as exc:
    recipientElem = browser.find_element_by_id(':9b')

recipientElem.send_keys(emailRecipient)

# add subject
try: 
    subjectElem = browser.find_element_by_id(':8o')
except Exception as exc:
    subjectElem = browser.find_element_by_id(':8t')

subjectElem.send_keys(emailSubject)

# add message
try: 
    messageElem = browser.find_element_by_id(':9t')
except Exception as exc:
    messageElem = browser.find_element_by_id(':9y')

messageElem.send_keys(emailMessage)

# click send
try:
    sendEmail = browser.find_element_by_id(':8e').click()
except Exception as exc:
    sendEmail = browser.find_element_by_id(':8j').click()

This post helped me: login to Gmail using Selenium in Python

Wilson Walker
  • 31
  • 1
  • 7