2017-07-04 11 views
-2

Facebookにログインしました。今度はホームページやニュースフィードのページから「更新情報を共有する」テキストエリアにメッセージを入力し、投稿をクリックします。 ロケータの下に試しました。うまくいきませんでした。javaとselenium webdriverを使ってfacebookのステータスメッセージを投稿するには

driver.findElement(By.name( "xhpc_message_text"))。sendkeys( "Hello World"); WebDriverWait wait =新しいWebDriverWait(driver、5);

答えて

0

私はあなたの質問に対する解決策を見つけました。

コード:

url = "http://facebook.com"; 
    String email = "email"; 
    String password = "password"; 
    System.setProperty("webdriver.chrome.driver", "src/chromedriver 3"); 
    WebDriver driver = new ChromeDriver(); 
    driver.get(url); 
    driver.manage().window().maximize(); 
    driver.findElement(By.id("email")).sendKeys("your email id"); 
    driver.findElement(By.id("pass")).sendKeys("Your password" + Keys.ENTER); 
    WebDriverWait wait = new WebDriverWait(driver, 500); 
    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//textarea[contains(@title,'Share an update')]"))); 
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//textarea[contains(@title,'Share an update')]"))); 
    driver.findElement(By.xpath("//textarea[contains(@title,'Share an update')]")).click(); 

    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@contenteditable='true']"))); 
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@contenteditable='true']"))); 
    driver.findElement(By.xpath("//div[@contenteditable='true']")).sendKeys("Hello World"); 

説明:

まずあなたが共有に更新テキストボックスをクリックし、ためにdiv要素のキーを送信する必要が以下のコードを試してみてくださいコンテンツ編集可能は、真のと設定されています。

0

import java.util.List; 
import java.util.concurrent.TimeUnit; 
import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.openqa.selenium.support.ui.ExpectedConditions; 
import org.openqa.selenium.support.ui.WebDriverWait; 



public class Facebook_login { 

    public static void main(String[] args) throws InterruptedException { 
     String user_name = "facebook_user_name"; 
     String pwd = "facebook_password"; 
     WebDriver driver = new FirefoxDriver(); 
     driver.manage().window().maximize(); 
     driver.get("https://www.facebook.com"); 
     driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); 
     driver.findElement(By.name("email")).clear(); 
     driver.findElement(By.name("email")).sendKeys(user_name); 
     driver.findElement(By.name("pass")).clear(); 
     driver.findElement(By.name("pass")).sendKeys(pwd); 
     driver.findElement(By.xpath("//input[contains(@value,'Log In')]")).click(); 
     Thread.sleep(10000);     
     System.out.println("logged in successfully"); 
     WebElement notification = driver.findElement(By.xpath("//a[contains(@action,'cancel')]")); 
     if(notification.isDisplayed()) { 
      System.out.println("Notification is present"); 
      notification.click(); 
     } 
     WebElement status =driver.findElement(By.xpath("//textarea[@name='xhpc_message']")); 
     status.sendKeys("Hello"); 
     Thread.sleep(3000); 
     WebDriverWait wait = new WebDriverWait(driver,30); 


     wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[text()='Post']"))).click(); 

    } 
} 
.. ..それはあなたのために働かなければならない以下のコードを試してみてください
関連する問題