1

I'm trying to click and activate the javascript link with Selenium. It's for a 5 star rating widget. five-stars is the exact item below. The other items, IE 4 star are not fully shown.

<div id="percentages_and_ratings">
<div id="percentages">
<div id="rating">
<ul id="personality-rating" class="star-rating profile_rating " onmouseout="Votes.publicStarOut(this)" onmouseover="Votes.publicStarOver(this)">
<li id="current-personality-3198779465475184989-1" class="current-rating" style="width: 0%;"></li>
<li>...
<li>...
<li>...
<li>...
<li>
<a class="five-stars" title="" href="javascript:processVoteNote('vote', 'personality', 5, '222222222222222', false, '', '', Profile.profileHeadingVote);">5</a>
</li>
<li class="cant-tell" style="display: none;">
<li class="click-away">

The selenium unit test output looks like

driver.find_element_by_xpath("(//a[contains(text(),'5')])[2]").click()

but that doesn't work. Selecting the xpath, CSS, HTML with firebug doesn't work either. Any ideas? I've been at it for a few nights now so it's time to ask :-)

I'm using Selenium web driver and python 2.7

Here is how I ended up solving it..

id = self.getID(driver)
script = "$(processVoteNote('vote', 'personality', 5, '"+id+"', false, '', '', Profile.profileHeadingVote));"
driver.execute_script(script)
1
  • What does it mean that that does't work? Does it show any error? Commented Jul 25, 2014 at 8:08

1 Answer 1

2

Based on the sample HTML you posted, browser.find_element_by_class_name('five-stars').click() should successfully select and click that link. If there is more than one element on the page with that class name on the page, you could use browser.find_elements_by_class_name('five-stars'), iterate through that list to identify the relevant links, and then click them.

If you want to use an XPATH search, I'd recommend using xPath Tester to try out different patterns.

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

1 Comment

That did work, and it did not. It allowed me to get to the next error (the element isn't visible) as I'm writing a crawler, I found a work around.

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.