2

I have a working script to manipulate a site. When running with webdriver.Chrome(chromedriver.exe) it works like a charm. But when I try with webdriver.PhantomJS(phantomjs.exe) it doesn't work.

More specifically, what doesn't work is the click() in a a tag, the HTML is the following:

<a href="javascript:;" class="foo" original-title=""><div class="icon_bar"></div></a>

I get this element via self.driver.find_elements_by_class_name('foo') and then set it to a var, there are tons of it. Then I create a loop and call current.click().

The thing is that it isn't really clicking, if I check the site manually nothing has changed.

  • Python 3.4.2
  • Selenium 2.44.0
  • Windows 8.1
1

It's known that PhantomJS doesn't always work as expected on some websites. You could use tricks/hacks like send_key(Keys.RETURN) on that tag. You could also try clicking an image, or other tag. Also you can get the href, and then calling it with driver.get(yourhiref).

Other thing is that, Do you only need one of those elements? Or to click on every element at find_elements_by_class_name('foo')? Because if it's the first case i would use xpath and css selector like this:

driver.find_element_by_xpath("//a[@Class='foo']/div")[n].click()

or

driver.find_element_by_xpath("//a[@Class='foo']")[n].click()

where n is the child you are looking for.

PS: I would go for a Headless Firefox instead of PhantomJS

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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