嗨,我是Selenium的新手,并试图将文本放在网站上的状态(框)中以发布给我的一位朋友。但是,我无法做到这一点



我是硒的新手,并试图将文本放在网站上的状态(框)中以发布给我的一位朋友。但是,我无法执行此操作,因为当我能够突出显示同一字段时,文本没有进入。在谷歌上搜索了很多时,我找不到一些错误。

Java Selenium代码在这里:

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>

试试这个。根据 HTML 的说法,输入似乎不是跨度,而是div。

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

相关内容

最新更新