Facebook帖子使用java硒



我正在尝试用一个小Java程序在facebook上发布一些文字和图片。

我不能发布任何东西,因为我不能点击适当的按钮与硒。

这里是代码的一部分,我需要点击上传照片/视频按钮:

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");
}
}

第一步是单击此xpath//*[@class="sjgh65i0"]//descendant::div[@class="m9osqain a5q79mjw gy2v8mqq jm1wdb64 k4urcfbm qv66sw1b"],它将出现弹出式"create publication"。现在,您可以使用xpath//*[@method="POST"]//descendant::*[@role="presentation"]//descendant::*[@role="textbox"]添加评论或按下"添加视频/照片"按钮;//*[@method="POST"]//descendant::div[@class="rq0escxv l9j0dhe7 du4w35lb j83agx80 cbu4d94t buofh1pr tgvbjcpo"]//descendant::*[@role="button"]

之后你可以按按钮发布//*[@method="POST"]//descendant::div[@class="k4urcfbm discj3wi dati1w0a hv4rvrfc i1fnvgqd j83agx80 rq0escxv bp9cbjyn"]//descendant::*[@role="button"]

最新更新