• Selenium webdriver Java 元素操作


    本来这些东西网上一搜一大堆,但是本着收集的精神,整理一份放着吧!哈!哈!哈!

    1. 输入框(text field or textarea)

    WebElement element = driver.findElement(By.id("passwd-id"));

    element.sendKeys(“test”);

    element.clear(); 

    element.getText();

    2. 下拉选择框(Select) 

    Select select = new Select(driver.findElement(By.id("select")));

    select.selectByVisibleText(“mediaAgencyA”);

    select.selectByValue(“MA_ID_001”);

    select.deselectAll(); 

    select.deselectByValue(“MA_ID_001”);

    select.deselectByVisibleText(“mediaAgencyA”);

    select.getAllSelectedOptions();

    select.getFirstSelectedOption();

    3.单选项(Radio Button) 

    WebElement bookMode =driver.findElement(By.id("BookMode"));

    bookMode.click();

    bookMode.clear(); 

    bookMode.isSelected(); 

    4. 多选项(checkbox) 

    WebElement checkbox =driver.findElement(By.id("myCheckbox."));

    checkbox.click();

    checkbox.clear(); 

    checkbox.isSelected();

    checkbox.isEnabled(); 

    5. 按钮(button) 

    找到按钮元素:

    WebElement saveButton = driver.findElement(By.id("save"));

    saveButton.click();

    saveButton.isEnabled (); 

    6. 左右选择框

    也就是左边是可供选择项,选择后移动到右边的框中,反之亦然。例如:

    Select lang = new Select(driver.findElement(By.id("languages")));

    lang.selectByVisibleText(“English”);

    WebElement addLanguage =driver.findElement(By.id("addButton"));

    addLanguage.click(); 

    7. 弹出对话框(Popup Dialogs)

    Alert alert = driver.switchTo().alert();

    alert.accept();

    alert.dismiss();

    alert.getText(); 

    8. 表单(Form)

    Form中的元素的操作和其它的元素操作一样,对元素操作完成后对表单的提交可以:

    WebElement approve = driver.findElement(By.id("approve"));

    approve.click();

    approve.submit();

    9. 上传文件(Upload File) 

    WebElement adFileUpload = driver.findElement(By.id("WAP-upload"));

    String filePath = "C: est\uploadfile\media_ads\test.jpg";

    adFileUpload.sendKeys(filePath); 

    10. Windows 和 Frames 的切换

    一般来说,登录后建议是先:

    driver.switchTo().defaultContent();

    driver.switchTo().frame("leftFrame");

    driver.switchTo().window("windowName");

    11. 拖拽(Drag and Drop)

    WebElement element =driver.findElement(By.name("source"));

    WebElement target = driver.findElement(By.name("target"));

    (new Actions(driver)).dragAndDrop(element, target).perform();

    12. 导航(Navigation and History)

    driver.navigate().to("http://www.example.com");

    driver.navigate().forward();

    driver.navigate().back();

  • 相关阅读:
    hdu1072 逃离迷宫系列 bfs
    hdu1495 倒水bfs
    hdu 1548 A strange lift (bfs)
    hdu1728 逃离迷宫bfs
    hdu1548 奇怪的电梯 dfs dijkstra bfs都可以,在此奉上dfs
    delphi 窗体的位置和高宽度-TForm:Letf、Top、Width、Height、ClientWidth、ClientHeight
    Delphi 鼠标控制函数GetCursorPos、SetCursorPos
    Delphi CoCreateGuid()函数 获取GUID
    Delphi出现“borland license information was found,but it is not valid for delphi”的错误,无法运行的解决方法
    一维条形码生成与识别技术
  • 原文地址:https://www.cnblogs.com/miniren/p/4638929.html
Copyright © 2020-2023  润新知