Reputation: 21
I am trying to post some text and pictures on facebook with a little Java program.
I am not able to post anything since I cannot click the appropriate button with selenium.
Here is the part of code where I need to click the upload Photo/video button on:
package good;
import org.openqa.selenium.Alert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.interactions.Actions;
public class HareKrishna {
public static void main (String []args ) throws InterruptedException {
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-notifications");
System.setProperty("webdriver.chrome.driver","/home/gt8201/AjaySingh/Automation Tools /chromedriver_linux64/chromedriver_linux64(1)/chromedriver");
WebDriver driver = new ChromeDriver(options);
driver.get("https://www.facebook.com/");
driver.findElement(By.name("email")).sendKeys("abc");
driver.navigate().forward();
driver.findElement(By.id("pass")).sendKeys("abx");
driver.findElement(By.name("login")).click();
driver.manage().window().maximize();
Thread.sleep(5000);
Alert alert = driver.switchTo().alert();
driver.switchTo().alert().accept();
driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS);
driver.navigate().forward();
Thread.sleep(5000);
driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS);
Actions Act = new Actions(driver);
driver.findElement(By.xpath("//*[@id=\"mount_0_0_08\"]/div[1]/div[1]/div/div[3]/div/div/div[1]/div[1]/div/div[2]/div/div/div/div[3]/div/div[2]/div/div/div/div[1]/div/div[1]/span"));
Act.click().sendKeys("Hare krishna");
}
}
Upvotes: 0
Views: 464
Reputation: 54
The first step is click on this xpath //*[@class="sjgh65i0"]//descendant::div[@class="m9osqain a5q79mjw gy2v8mqq jm1wdb64 k4urcfbm qv66sw1b"]
and it do to appear the pop-up "create publication".
Now you could add a comment with xpath //*[@method="POST"]//descendant::*[@role="presentation"]//descendant::*[@role="textbox"]
or push button "add videos/photos" //*[@method="POST"]//descendant::div[@class="rq0escxv l9j0dhe7 du4w35lb j83agx80 cbu4d94t buofh1pr tgvbjcpo"]//descendant::*[@role="button"]
Later you could push button publish //*[@method="POST"]//descendant::div[@class="k4urcfbm discj3wi dati1w0a hv4rvrfc i1fnvgqd j83agx80 rq0escxv bp9cbjyn"]//descendant::*[@role="button"]
Upvotes: 1