Clicking A Button With Selenium In Python
Goal: use Selenium and Python to search for company name on LinkedIn's search bar THEN click on the 'Companies' button in the navigation to arrive to information about companies th
Solution 1:
It seem that you simply used incorrect selectors.
Note that
@idofdivlike"ember1002"is dynamic value, so it will be different each time you visit page:"ember1920","ember1202", etc...find_element_by_link_text()can be applied to links only, e.g.<a>Companies</a>, but not buttons
Try to find button by its text content:
browser.find_element_by_xpath('//button[normalize-space()="Companies"]').click()
Solution 2:
With capybara-py (which can be used to drive Selenium), this is as easy as:
page.click_button("Companies")
Bonus: This will be resilient against changes in the implementation of the button, e.g., using <input type="submit" />, etc. It will also be resilient in the face of a delay before the button appears, as click_button() will wait for it to be visible and enabled.
Post a Comment for "Clicking A Button With Selenium In Python"