4

I am using Selenium Webdriver in Python and I got stuck trying to activate a javascript button.

What I need to do here is to click the Go to Previous Month button twice so that I have August 2014. And then I need to click on one of the days.

The images below show the code. Please tell me if I need to provide more info.

enter image description here

THIS IS THE "GO TO PREVIOUS MONTH BUTTON" + INSPECT ELEMENT

enter image description here

AND HERE I'VE CLICKED ON THE 1ST OF AUGUST + INSPECT ELEMENT ON "1"

How do I do it?

Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
Alichino
  • 1,668
  • 2
  • 16
  • 25

1 Answers1

3

First find your element with CSS selectors (you need to be familiar how CSS selectors work - this is prerequisite for most web development):

elem = webdriver.find_element_by_css_selector("a[title='Go to previous month']")[0]

Related WebDriver documentantion.

Then when you get your elem (there might paeg loading time, etc. issues you need to deal with) you can click it.

 elem.click()

See also: Wait for page load in Selenium

Related click() documentation.

Community
  • 1
  • 1
Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
  • Oh, I forgot to mention that there are actually two calendars on that page, and both have "Go to the previous month" as title of the "<" button... I guess I need to be more specific exactly where I want to press the button. Using xpath? – Alichino Oct 15 '14 at 09:32
  • `find_element_by_css_selector()` returns multiple elements. Just pick the first or the last one. – Mikko Ohtamaa Oct 15 '14 at 11:37
  • It's taken a few days, but I finally got it :D Thanks! – Alichino Oct 17 '14 at 14:32