简体   繁体   中英

How to finding webElement (on Facebook) using selenium using java

I'm create a test Script where i post on my wall in Facebook but I was unable to locate the element (getting an NoSuchElementException) even though the element exist and I was trying to find a cssSelector using FirePath.

在此处输入图片说明

I can't find any of the elements ('post', 'photo/video', and etc) or write on the wall.
I have tried below mentioned code:

@Test
public void doTest(){
    driver.get("https://www.facebook.com/");
    driver.findElement(By.id("email")).sendKeys("kryptonitecricket@gmail.com");
    WebElement element= driver.findElement(By.id("pass"));
    element.sendKeys("windcore123");
    element.submit();
    doThread();

    WebElement element1;
     element1= driver.findElement(By.id("pagelet_composer"));
    element1.click();
    element1=driver.findElement(By.cssSelector("#mainContainer>#contentCol"........);
    WebElement element2=driver.findElement(By.cssSelector("._1mf7._4jy0._4jy3._4jy1._51sy.selected._42ft"));
    element2.click();
}

I am very new to selenium and testing Thank you

You can use xpath instead of CSS, as we know it says "What's on your mind" ; therefore we can use this to find the status:

driver.findElement(By.xpath("//textarea[@title=\"What's on your mind?\"]"))

i think this should work

最好的方法是通过xpath识别元素。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM