0

I'm trying to use python and selenium webdriver to click in a submit button of a specific form, below is the source code of the element that I want to click:

<input type="submit" name="post" tabindex="5" value="Submit" class="btn btn-primary btn-xs btnmain" accesskey="s">

And here is the python expression that I'm using to click on it:

text_area = wd.find_element_by_id('qreply')
text_area.send_keys("TEST STRING")
wd.find_element_by_xpath("//button[contains(@class,'btn btn-primary btn-xs btnmain')]").click()

The problem is, that for some reason, my script appears to not click at the button and the information is not sent.

Any suggestion how I can solve it?

2 Answers 2

1
wd.find_element_by_xpath("//button[contains(@class,'btn btn-primary btn-xs btnmain')]").click()

Is that xpath right? Your html says it's a input tag, not button.

Try

wd.find_element_by_xpath("//input[contains(@class,'btn btn-primary btn-xs btnmain')]").click()

Also consider a better xpath like:

wd.find_element_by_xpath("//input[@name='post']").click()
Sign up to request clarification or add additional context in comments.

Comments

0

for the send keys part

text_area = wd.find_element_by_id('qreply')
text_area.click() # you need to click it before typing, just like how you would do it manually
text_area.send_keys("TEST STRING")

for the submit button, my guess is your xpath is too generic that it extracted another button that has the same classes. Try to print the extracted button and see if it is the one you want first as your code for clicking seems fine.

1 Comment

Thanks for the text area tip, and about the button, he is the only that uses this class, I've tried to click by name, bu got the same error.

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.