Rudziankoŭ
Rudziankoŭ

Reputation: 11251

How does correctly find elements of a webpage with Selenium Webdriver?

I practice with Facebook,

WebDriver driver = new HtmlUnitDriver();


driver.get("http://www.facebook.com");

after successful logining I attempt to send message. But I can not find message area:

WebElement selectMessages = driver.findElement(By.id("fbMessagesFlyout"));
        selectMessages.click();


        WebElement elementMess = driver.findElement(By.id("q"));
        elementMess.sendKeys("Dalia");
        elementMess.submit();

This code just deploys javascript with messages on the header and then send search request also at the fb header. How do I can find correct link to a dialig page and then find there text aria?

Upvotes: 0

Views: 282

Answers (1)

Prashanth Sams
Prashanth Sams

Reputation: 21129

This WORKS!!

@BeforeTest
public void setUp() throws Exception {
    driver = new FirefoxDriver();
    baseUrl = "https://www.facebook.com";
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
}

@Test
public void testUntitled() throws Exception {
    driver.get(baseUrl + "/login.php");
    driver.findElement(By.id("email")).sendKeys("[email protected]");
    driver.findElement(By.id("pass")).sendKeys("yourpassword");
    driver.findElement(By.name("login")).click();
    Thread.sleep(3000);
    WebElement msgframe = driver.findElement(By.id("fbMessagesJewel"));
    msgframe.findElement(By.tagName("a")).click();
    List<WebElement> element = driver.findElements(By
            .className("messagesContent"));
    element.get(0).click();
    WebElement chat = driver.findElement(By.className("fbNubFlyoutFooter"));
    chat.findElement(By.tagName("textarea")).sendKeys("Hi");
    driver.findElement(By.tagName("textarea")).sendKeys(Keys.RETURN);
    Thread.sleep(2000);
}

Upvotes: 1

Related Questions