0

I am working with selenium (python) and I would like for it to click on a button. The code goes something like this:

from selenium import webdriver
driver = webdriver.Firefox()
driver.get('my_url')
try:
 driver.find_element_by_partial_link_text('Mais').click()
except:
 pass

Nothing at all happens. After inspecting the source, and I am pretty sure this is the element I want to find:

<input class="ksb _kvc" value="Mais resultados" id="smb" data-lt="Carregando..." jsaction="str.smr" data-ved="0ahUKEwjPtK6Fwv3PAhVGI5AKHTkSDVsQxdoBCE8" type="button" />
Cœur
39k25 gold badges206 silver badges281 bronze badges
asked Oct 28, 2016 at 20:05

2 Answers 2

1

Have you tried

driver.find_element_by_id('smb').click()

Rather than

driver.find_element_by_partial_link_text('Mais').click()

I suspect nothing happens because an exception is thrown in your original code if the find fails. When attempting to locate elements I would usually use id/name as these are normally unique. For a full list see selenium-python.readthedocs.io/locating-elements.html

answered Oct 28, 2016 at 20:08

3 Comments

beautiful!!! thanks a lot. will upvote in 7 mins, as soon as it is enabled.
cool, when attempting to locate elements I would usually use id/name as these are normally unique. For a full list see selenium-python.readthedocs.io/locating-elements.html
thanks again! completely new to selenium, and I know little about js in general. great advice.
1

You are having issue clicking the button because you are using driver.find_element_by_partial_link_text() which is only good for finding link (anchor elements) by its partial text, and performing actions on it.

You should rely on the other find_element_by_xxxx() methods which allow us to find by element ID, Name, XPath, CSS selector, or Class name.

Refer the documentation on locating elements at : http://selenium-python.readthedocs.io/locating-elements.html

answered Oct 29, 2016 at 11:23

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.