0

I am trying to scrape the Google News page in the following way:

from selenium import webdriver
import time
from pprint import pprint


base_url = 'https://www.google.com/'

driver = webdriver.Chrome('/home/vincent/wintergreen/chromedriver') ## change here to your location of the chromedriver
driver.implicitly_wait(30)
driver.get(base_url)


input = driver.find_element_by_id('lst-ib')
input.send_keys("brexit key dates timetable schedule briefing")

click = driver.find_element_by_name('btnK')
click.click()

news = driver.find_element_by_link_text('News')
news.click()

tools = driver.find_element_by_link_text('Tools')
tools.click()

time.sleep(1)

recent = driver.find_element_by_css_selector('div.hdtb-mn-hd[aria-label=Recent]')
recent.click()

# custom = driver.find_element_by_link_text('Custom range...')
custom = driver.find_element_by_css_selector('li#cdr_opt span')
custom.click()

from_ = driver.find_element_by_css_selector('input#cdr_min')
from_.send_keys("9/1/2018")

to_ = driver.find_element_by_css_selector('input#cdr_max')
to_.send_keys("9/2/2018")

time.sleep(1)

go_ = driver.find_element_by_css_selector('form input[type="submit"]')
print(go_)
pprint(dir(go_))
pprint(go_.__dict__)
go_.click()

This script manage to enter search terms, switch to the news tab, open the custom time period tab, fill in start and end date, but fails to click on the 'Go' button after that point.

From the print and pprint statement at the end of the script, I can deduct that it does find the 'go' button succesfully, but is somehow unable to click on it. The error displays as selenium.common.exceptions.ElementNotVisibleException: Message: element not visible

Could anyone experienced with Selenium have a quick run at it and give me hints as why it returns such error?

Thx!

1 Answer 1

3

Evaluating the css using developer tools in chrome yields 4 elements.

Click here for the image

use the following css instead:

go_ = driver.find_element_by_css_selector('#cdr_frm > input.ksb.mini.cdr_go')
Sign up to request clarification or add additional context in comments.

2 Comments

thx a lot! Briefly can you tell me how, from the console, you could isolate #cdr_frm as the proper parent to reference?
Right click element -> Inspect -> Developer Tool Opens -> In the Elements tab -> right click highlighted element -> Right Click -> Copy -> Copy Selector

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.