Unable to locate element error while trying to locate a textarea input box using Selenium through Python

32 views Asked by At

I´m trying to find a text box on a webpage with Python and Selenium. I Tried By.css_selector, by ID, by name and with the iFrame in view but the message is always:

Unable to locate element: textarea.paragraph-input

here's part of the html.

<textarea style="padding-right:0; height:4rem;" class="paragraph-input" data-name="description" placeholder="(This portion is constantly changing)"></textarea>]]

My code is:

browser.get(siteName)
browser.implicitly_wait(timeout)
#browser.switch_to.frame(browser.find_element(By.TAG_NAME, 'iframe'))
search_form = browser.find_element(By.CSS_SELECTOR, "textarea.paragraph-input")
search_form.click()
search_form.send_keys(results)

Any help is appreciated

I've tried changing the find_element value with both textarea and paragraph-input, neither of which worked. The only thing I have not tried due to ineptitude is xPath

1

There are 1 answers

0
Tal Angel On

Misfortunately Selenium does Not do well with hyphens, white spaces and other characters.

If you wish to find an attribute that contains a special char do this:

css_exp = 'textarea[class*="paragraph"][class*="input"]'
search_form = browser.find_element(By.CSS_SELECTOR, css_exp)

The sign *= means partial match. It will find (in this example) all the Textarea that have a class that contains the word "paragraph" and from this group, all the ones that have a class that contains the word "input".

Also, please make sure that your element is not inside Iframe. If it is another Iframe you will have to focus on the Iframe first.