Travis Walstrom
Travis Walstrom

Reputation: 39

Python Selenium Click and Input Into Text Box

I am running Python 3.5 trying to "click" a text box with selenium so I can input rows of numbers. I have already scripted the login and navigation to the text box but I can't get my code to type "1234".

Here is the code, maybe there is something bigger in the HTML I am missing but the inspector tool shows the click box as below...

<td align="left" style="vertical-align: top;"><textarea
 class="stb-SearchBox" style="width: 100%; height: 5em;"
 dir=""></textarea></td>

I've tried the below and a few other different ways... maybe i'm missing something?

clickBox = driver.find_elements_by_xpath("//*[contains(class(), 'stb-SearchBox')]").click()

clickBox = driver.find_elements_by_class('stb-SearchBox').click()

eventually I will have my code use

clickBox.send_keys("1234")

Upvotes: 2

Views: 8637

Answers (1)

alecxe
alecxe

Reputation: 473853

//*[contains(class(), 'stb-SearchBox')]

Here you are incorrectly checking the class attribute. It needs to be @class instead of class().

driver.find_elements_by_class('stb-SearchBox').click()

There is no find_elements_by_class() method available in Python selenium bindings. Use find_element_by_class_name() instead.

Or, you can use a simple CSS selector to locate the element:

driver.find_element_by_css_selector("textarea.stb-SearchBox")

Upvotes: 1

Related Questions