Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

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?

share|improve this question
    
Find a element by title using css selectors and do the click() event on the returned element? – Mikko Ohtamaa Oct 15 '14 at 8:46
    
How do I use the css selectors? I'm a bit of a n00b... – Alichino Oct 15 '14 at 8:51
    
Cool! No problem - clarified the answer in the Answer section. – Mikko Ohtamaa Oct 15 '14 at 8:56
up vote 1 down vote accepted

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.

share|improve this answer
    
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 9: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
    
Cool. No problem :) – Mikko Ohtamaa Oct 17 '14 at 14:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.