How to locate Facebook POST button using Java Selenium WebDriver?



  • Code:

    driver.findelement(By.xpath(".//*[@id='js_2y']/div[4]/div[2]/div/div[2]/div/button")).click();
    

    Every time I try by locating XPath, it's gives an exception, could not locate element.

    May 04, 2016 8:35:29 PM org.openqa.selenium.support.ui.ExpectedConditions findElement
    WARNING: WebDriverException thrown by findElement(By.xpath: .//*[@id='js_2y']/div[4]/div[2]/div/div[2]/div/button)
    

    Is it something that can be done using CSS selector. Not sure how to locate it. I see below path for it:

    <button class="_1mf7 _4jy0 _4jy3 _4jy1 _51sy selected _42ft" data-testid="react-composer-post-button" type="submit" value="1">
    


  • If you are asking about this post button - try below code to click on post button.

    enter image description here

    for this-

    WebElement postBtn = driver.findElement(By.xpath("//button[contains(.,'Post')]"));
    postBtn.click();
    

    OR

    WebElement postBtn = driver.findElement(By.xpath("//button[@class='_1mf7 _4jy0 _4jy3 _4jy1 _51sy selected _42ft']"));
    postBtn.click();
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2