简体   繁体   中英

How to make post on Facebook using Selenium Webdriver + Java?

How to make post on Facebook using Selenium Webdriver + Java?

This window. http://prntscr.com/i603dv

My code:

driver.findElement(By.xpath("//input[@id='email']")).sendKeys("me-email");
driver.findElement(By.xpath("//input[@id='pass']")).sendKeys("my-password");
driver.findElement(By.xpath("//label[@id='loginbutton']")).click();
//here I turn off notifications        
driver.findElement(By.xpath("//a[@action='cancel']")).click();

Actions actions = new Actions(driver);
//with help of this code I can focus on window.
WebElement element = driver.findElement(By.xpath("(//span[@class=\"uiIconText _5qtp\"])[1]"));
actions.doubleClick(element);

//Here I want to post text, but it doesn't work.
driver.findElement(By.xpath("//div[@class=\"_1mf _1mj\"]")).sendKeys("Test");

Why it doesn't work? Then I press button Post but it doesn't work also.

The popup/window opens after double click . So you could try to switch to new popup using switch to window of webdriver. It should help . Here is a link of simple webdriver test which switch window http://learn-automation.com/handle-multiple-windows-in-selenium-webdriver/

Try to do the same for you . If you have any questions let me know .

"_1mf _1mj " is a complex class. Selenium won't work on complex classes.

You can try Action chain - press "tab" button multiple times until you reach to "post"

Also, Facebook provides a drop down option after pressing tab button . You can choose from the drop down what you want to do., Using selenium.

Alternatively try mbasic version of FB.

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