我无法点击facebook的上传按钮

时间:2015-05-23 15:15:21

标签: java selenium

我正在尝试使用selenium上传我的个人资料图片 java 。 但它没有点击上传按钮。请解释一下我必须上传照片。

  1. 打开Facebook.com
  2. 输入用户名密码。
  3. 点击上传个人资料图片。
  4. 点击上传照片

1 个答案:

答案 0 :(得分:0)

yes i agree with Saifur writing selenium scripts for facebook or google would be very difficult for beginners but the fact is both facebook and google are using selenium for testing...

To click on upload button u can use the below javascript

JavascriptExecutor js=(JavascriptExecutor) driver;

js.executeScript("document.getElementsByClassName('_156p')[0].click();");

I checked with some attempts and refreshes the classname was not changing...If u feel the classname is changing and if u want your script to be more robust u can try javascript below here we take all the div elements into an array an iterate through it and get the innerHTML of all the divs if the innerHTML is equal to "Update Profile Picture" we click on it....

var stringToMatch = "Update Profile Picture";
var divs = document.getElementsByTagName('div');
for (var i = 0; i < divs.length; i++) {
  if (divs[i].innerText == stringToMatch) {
  divs[i].click();
  } 
}

Hope this helps...Kindly get back if you have any queries