2017-11-07 6 views
-4

私はセレンに新しく、私の友人の1人に投稿するためにサイトのステータス(ボックス)にテキストを入れようとしています。しかし、私は同じフィールドを強調表示することができますが、テキストが入っていないので、私はこれを行うことができません。 googleでたくさん検索されている間に私が見つけることができない何かが間違っています。こんにちは、私はセレンに慣れておらず、サイトのステータス(ボックス)にテキストを入れて友達の1人に投稿しようとしています。しかし、私はこれを行うことができません

のJavaセレンコードはここにある:テキストボックスフィールドの

package facebookmessaging; 

import java.util.concurrent.TimeUnit; 

import org.apache.commons.codec.binary.Base64; 
import org.openqa.selenium.By; 
import org.openqa.selenium.JavascriptExecutor; 
import org.openqa.selenium.Keys; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.openqa.selenium.interactions.Actions; 
import org.openqa.selenium.support.ui.ExpectedConditions; 
import org.openqa.selenium.support.ui.WebDriverWait; 


public class FacebookMessaging { 

    private static WebDriver driver = null ; 
    private static String decPassword = "HUMHUMMMMMM=="; 

    public static void main(String[] args) { 




     String strPassword = EncodingAndDecodingClass.decodingMethod (decPassword); 

     driver = new FirefoxDriver(); 
     WebDriverWait wait=new WebDriverWait(driver, 30); 
     driver.navigate().to("https://www.facebook.com/"); 
     driver.manage().window().maximize(); 
     driver.findElement(By.name("email")).clear(); 
     driver.findElement(By.name("email")).sendKeys("youremailid"); 
     driver.findElement(By.name("pass")).clear(); 
     driver.findElement(By.name("pass")).sendKeys(strPassword); 
     driver.findElement(By.xpath("//input[starts-with(@id,'u_0')]")).click(); 

     WebElement waitElement; 
     waitElement= wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[(@class='_1frb') and (@name='q')]"))); 
     waitElement.clear(); 
     waitElement.sendKeys("YourFriendName"); 
     waitElement.sendKeys(Keys.RETURN); 

     waitElement= wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[(@class='_52eh _5bcu') and (text()='YourFriendName')]"))); 
     waitElement.click(); 

// code is working fine upto above line of code 


// The below two lines of code is not working 
WebElement element = driver.findElement(By.xpath("//div[@class='_1mf _1mj']/span"); 
waitElement.sendKeys("Hello ma'am"); 




//Method for highlighting an element on web page 
/* public static void fnHighlightMe(WebDriver driver,WebElement element) throws InterruptedException{ 
      //Creating JavaScriptExecuter Interface 
      JavascriptExecutor js = (JavascriptExecutor)driver; 

       //Execute javascript 
       js.executeScript("arguments[0].style.border='4px groove green'", element); 
    } */ 

HTMLは次のとおりです。

<div class="notranslate _5rpu" contenteditable="true" aria-autocomplete="list" aria-controls="js_i7" aria-multiline="true" data-testid="status-attachment-mentions-input" role="textbox" spellcheck="true" style="outline: medium none; white-space: pre-wrap; word-wrap: break-word;" aria-describedby="placeholder-1r5me"> 
<div data-contents="true"> 
<div class="" data-block="true" data-editor="1r5me" data-offset-key="4n5ih-0-0"> 
<div class="_1mf _1mj" data-offset-key="4n5ih-0-0"> 
<span data-offset-key="4n5ih-0-0"> 
<br data-text="true"> 
</span> 
</div> 
</div> 
</div> 
</div> 
+2

が対象で、問題の唯一の重要な一部を与える –

+2

あなたは[TOS]あたりとしてのFacebookをこすりすることはできません(https://www.facebook.com/legal/terms)ここで問題 – DebanjanB

+0

は私たちにspecficコードを与えますoccured – iamsankalp89

答えて

0

はこれを試してみてください。 HTMLによると、入力がスパンではなくdivであるように見えます。

WebElement waitElement = driver.findElement(By.xpath("///div[@data-testid='status-attachment-mentions-input']"); 
waitElement.sendKeys("Hello ma'am"); 
+0

こんにちはJOberloh、入力いただきありがとうございます。現在は動作しています –

+0

もしそうなら、私が提出した回答の下にあるチェックマークで回答を受け入れて、他の人が正しい答えを見ることができるようにしてください。 – JOberloh

関連する問題