2

I am quite new to python selenium and I am trying to click on a button which has the following html structure:

<a href="#" onclick="loadCalendarsForDateFn('jmpto1605')"><span class="jumpToMonthMM">May</span><span class="jumpToMonthYY">2016</span></a><br/>

I would like to be able to click the "May 2016" button above. Can someone guide me how to do that?

Thanks in advance!

2 Answers 2

2

You can check both month and year with an XPath:

//a[span[@class="jumpToMonthMM"] = "May" and
    span[@class="jumpToMonthYY"] = "2016"]
Sign up to request clarification or add additional context in comments.

6 Comments

Thanks a lot! I found the link button! One followup question is when I issue the click() command, it just didn't jump to the May 2016. elem = browser.find_element_by_xpath('//a[span[@class="jumpToMonthMM"] = "May" and span[@class="jumpToMonthYY"] = "2016"]') print('Found It!') elem.click()
@damingzi great! Do you mean nothing happens when you issue a click()? What if you would move to the element and then click: ActionChains(driver).move_to_element(elem).click().perform()? Don't forget the import: from selenium.webdriver.common.action_chains import ActionChains.
Thanks for your continuous replies. But the ActionChains click didn't work neither. I am thinking if the elem "May 2016" is the correct one to click. Do you have any clue?
@damingzi could you please elaborate this problem into a separate question? This might make more sense since more people may help. Make sure to provide all the necessary details. Thanks!
Thanks! I found a workaround for click(). I substituted .click() with .send_keys("\n"), the latter one does almost the same thing :)
|
1

Alexce has a good solution but you could also look for the onclick attribute with loadCalendarsForDateFn('jmpto1605'):

find_element_by_xpath("""//a[@onclick ="loadCalendarsForDateFn('jmpto1605')"]""")

The 05 and 16 obviously correspond to May and 2016 as so I think it is safe to assume it is unique.

1 Comment

Thank you Padraic for your input :) I tried similar approach below, and it also worked! find_element_by_xpath(".//a[contains(@onclick, 'jmpto1605')]")

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.