2

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")
1
  • First off find_elements returns a list and there is no xpath class() function, it would be find_element_by_xpath("//*[@class='stb-SearchBox']") Commented Jun 24, 2016 at 16:14

1 Answer 1

1
//*[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")
Sign up to request clarification or add additional context in comments.

2 Comments

Hmm it is still not working on selecting and inputting 1234... I apologize if I made silly mistakes, I'm still pretty new to Python, Selenium Module, and the world of coding ;P
Figured it out a while back but thought i'd comment to bring this to a close. Just 'copying the xpath' instead of hunting for it. And annotating the xpath with ' instead of " made a big difference.

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.