简体   繁体   English

如何使用Selenium Webdriver正确查找网页的元素?

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

I practice with Facebook, 我在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. 这段代码只是将JavaScript与消息一起部署在标头上,然后在fb标头上发送搜索请求。 How do I can find correct link to a dialig page and then find there text aria? 我如何才能找到指向Dialig页面的正确链接,然后在其中找到文本aria?

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("youridhere@gmail.com");
    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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Selenium Webdriver 在网页中找到“光标”位置? - How to find “Cursor” position in webpage with Selenium Webdriver? 硒webdriver找不到正确数量的元素 - selenium webdriver does not find the correct number of elements 如何使用 selenium webdriver 查找动态元素? - How to find a dynamic elements using selenium webdriver? 如何使用Selenium WebDriver选择网页上的两个元素之一? - How to chose either of 2 elements on a Webpage using Selenium WebDriver? 如何使用Selenium Webdriver在新网页中查找元素? - How to find an element in new Webpage using selenium webdriver? 如何使用Selenium Webdriver查找网页上多个按钮的数量 - How to find the count of multiple buttons on a webpage using Selenium Webdriver 在Selenium webdriver中,有没有办法发现所有页面元素都已正确加载并且没有元素重叠? - In Selenium webdriver, Is there a way to find out that all page elements have been loaded correctly and no elements are overlapped? 如何使用Selenium Webdriver Firefox查找和验证元素“标题” - How to find and Validate an elements “Title” with selenium webdriver Firefox 如何使用Selenium WebDriver配置网页语言 - How to configure webpage language using selenium webdriver Selenium Webdriver:如何验证是否已加载所需的网页 - Selenium Webdriver: How to verify that the required webpage is loaded
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM