1

I've looked and tried all i can, i'm in need of assistance. I'm trying to get the text from an element in a page. Its a popup but not an alert or a new window, just another popup within a frame. WebDriver appears to find the element, but when i run the print statement to check the text returned, it is consistently a blank line. I've tried, instead of get_attribute, .text as well... no luck.

Here's the html:

<textarea id="textareafield-2320-inputEl" class="x-form-field x-form-text x-form-textarea" name="activityComments" rows="4" cols="20" autocomplete="off" aria-invalid="false" style="width: 100%;"></textarea>

Here's my code:

contents = driver.find_element_by_xpath(".//*[@class='x-form-item-input-row']/td[2]/textarea").get_attribute("value")
print contents
5
  • thanks for the update, this was my first question ever lol Commented Jan 3, 2017 at 23:50
  • You can use find_element_by_id instead of xpath. Did you try that? Commented Jan 3, 2017 at 23:51
  • the ids are being generated randomly so it changes all the time, same with the name. Commented Jan 3, 2017 at 23:55
  • why the down vote? just looking for some help after searching for days on this site and others. everyone says to use the value attribute, there isnt one. they say use the text, tried it. just looking for help. if youre gonna vote down, at least let me know why so i can improve my question Commented Jan 4, 2017 at 0:17
  • Are you sure, you're locating correct text area element?? Commented Jan 4, 2017 at 1:15

1 Answer 1

2

Your XPath is quite broad. Several elements on page might be matched with this XPath. To check it try print(len(driver.find_elements_by_xpath(".//*[@class='x-form-item-input-row']/td[2]/textarea"))). If result is more than 1, you seem to handle wrong element.

Try to use more explicit XPath:

//textarea[starts-with(@id, "textareafield-")][@name="activityComments"]
Sign up to request clarification or add additional context in comments.

2 Comments

welp, i'm embarassed... this worked! thanks so much, i need to work on my locator skills clearly. thanks again. i upvoted but since i just joined it wont display.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.