简体   繁体   中英

I am unable to click on Upload button of facebook

I am trying to upload my profile picture using selenium with java . But it is not clicking on upload button.Please explain it I have to upload photo.

  1. Open Facebook.com
  2. Enter username password.
  3. Click on upload profile picture.
  4. Click on upload photo

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM