Aby Abraham
Aby Abraham

Reputation: 354

Python Selenium PhantomJS not clicking on same button that Firefox Webdriver is able to click

I was implementing a bot to click on upvote button in reddit

Here is the html code of the upvote button.

<div class="arrow up login-required access-required" data-event-action="upvote" role="button" aria-label="upvote" tabindex="0"></div>
<div class="score likes">•</div>
<div class="score unvoted">•</div>
<div class="score dislikes">•</div>
<div class="arrow down login-required access-required" data-event-action="downvote" role="button" aria-label="downvote" tabindex="0"></div>

I am able to click on the upvote button using

target = driver.find_element_by_xpath("//div[@class='arrow up login-required access-required']")
target.click()


OR

target = driver.find_element_by_css_selector("div.arrow.up")
target.click()

The clicking works fine in FIREFOX web driver , but when I try to implement the same in PhantomJS , the browser is not clicking.

Here is the screenshots of 2 browsers

enter image description here

Upvotes: 0

Views: 1465

Answers (1)

Hassan Mehmood
Hassan Mehmood

Reputation: 1402

Try performing click() operation via jQuery or JavaScript using execute_script method of selenium. Below is the sample code that will perform the click operation.

driver.execute_script("$('div.arrow.up').click()")

For the page which has multiple upvote fields then you can use an index to choose which one you want to click e.g

driver.execute_script("$('div.arrow.up')[0].click()")
driver.execute_script("$('div.arrow.up')[1].click()")
driver.execute_script("$('div.arrow.up')[2].click()")
and so on..

Upvotes: 2

Related Questions