Ram
Ram

Reputation: 11

How to click the next link in google search results?

I am trying to move onto the next-page of the google search results using Selenium; something which can achieved by clicking Next in the browser when done manually. Below is the snippet

browser.get('https://www.google.com')
inputElement = browser.find_element_by_name("q")
inputElement.send_keys('python' + Keys.RETURN)

Any pointers or snippets would be helpful.

Upvotes: 1

Views: 1319

Answers (1)

alecxe
alecxe

Reputation: 473833

This is quite straightforward: locate the link by it's text:

driver.find_element_by_link_text("Next").click()

Demo:

>>> driver.current_url
u'https://www.google.com/?gws_rd=ssl#q=python'
>>> driver.find_element_by_link_text("Next").click()
>>> driver.current_url
u'https://www.google.com/?gws_rd=ssl#q=python&start=10'

Upvotes: 1

Related Questions