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?

3
  • Find a element by title using css selectors and do the click() event on the returned element? Commented Oct 15, 2014 at 8:46
  • How do I use the css selectors? I'm a bit of a n00b... Commented Oct 15, 2014 at 8:51
  • Cool! No problem - clarified the answer in the Answer section. Commented Oct 15, 2014 at 8:56

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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?
find_element_by_css_selector() returns multiple elements. Just pick the first or the last one.
It's taken a few days, but I finally got it :D Thanks!

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.