Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to click Facebook Like button using Webdriver

I'm trying to click Facebook Like button using Webdriver. You can see an example Like button at this page.

After switching to iframe I've tried:

page.execute_script("document.querySelector('.pluginConnectButton > div:first-child button').click()")

This script works in Firebug and Chrome Developer Tools after switching to iframe.

But it doesn't work in FirefoxDriver and ChromeDriver (script passes but button isn't changed to clicked one)

How can I click this button using Webdriver?

like image 650
Andrei Botalov Avatar asked Oct 05 '22 08:10

Andrei Botalov


1 Answers

While this worked for me it seems brittle. I had to use some javascript to get the id of the iframe since FB changes the id on each page load. Luckily they're not changing the class of the iframe.

id = page.evaluate_script("$('.fb_ltr').attr('id');")
within_frame(id) do
  page.first(:css, '.pluginButton').click
end
like image 119
RobertH Avatar answered Oct 10 '22 02:10

RobertH