Logging Facebook using selenium

后端 未结 3 582
盖世英雄少女心
盖世英雄少女心 2021-01-23 03:06

I know this is a not a proper technical question, but i am facing problem while using selenium to make a facebook post bot. This is my code so far

    from selen         


        
3条回答
  •  伪装坚强ぢ
    2021-01-23 03:40

    This Code is to log in to Facebook and Post "Hello World" text in status

    public void facebookLogin() throws InterruptedException {
    
     //1. Set gecko driver path
    
    System.setProperty("webdriver.gecko.driver","C:\\Selenium\\selenium-java-3.0.1\\geckodriver.exe");
    
    WebDriver d= new FirefoxDriver();
    
      //2. Enter URL 
    
      d.get("https://www.facebook.com/");
    
      //3. maximize window
    
      d.manage().window().maximize();
      Thread.sleep(2000);
    
       //4. Login Into Fcaebook
      d.findElement(By.id("email")).sendKeys("email");
      d.findElement(By.id("pass")).sendKeys("password");
      d.findElement(By.id("loginbutton")).click();
       Thread.sleep(3000);
    
        //5. Post "Hello World" into status 
    
       d.get("https://www.facebook.com/");
       WebElement post= d.findElement(By.xpath("//*[@name='xhpc_message']"));
       post.click();
       post.sendKeys("Hello World");
       d.findElement(By.xpath("(//button[@value='1'])[5]")).click();
    
       Thread.sleep(2000);
    
      }
    

提交回复
热议问题