zoukankan      html  css  js  c++  java
  • Selenium webdriver 操作日历控件

    文章转自:http://www.tuicool.com/articles/q6zYJ3m

    一般的日期控件都是input标签下弹出来的,如果使用webdriver 去设置日期,

    1. 定位到该input

    2. 使用sendKeys 方法

    比如:

    但是,有的日期控件是readonly的

    比如12306的这个

    <input id="train_date" class="inp-txt" type="text" value="2015-03-15" name="back_train_date" autocomplete="off" maxlength="10" readonly="readonly" disabled="disabled">

    这个时候,没法调用WebElement的sendKeys()

    方案一:使用JS remove readonly attribute,然后sendKeys

    还是以万恶的12306为例:

    使用出发日期,将input标签的readonly熟悉去掉

    JavascriptExecutor removeAttribute = (JavascriptExecutor)driver;  
             //remove readonly attribute
             removeAttribute.executeScript("var setDate=document.getElementById("train_date");setDate.removeAttribute('readonly');") ;

    方案二:采用click直接选择日期,日期控件是一个iframe,首先switch iframe,之后找到想要设置的日期button click,然后switch出来

    WebElement dayElement=driver.findElement(By.xpath("//span[@id='from_imageClick']"));

    dayElement.click();

    // WebElement frameElement=driver.findElement(By.xpath("//iframe[@border='0']"));

    driver.switchTo().frame(1);

    driver.findElement(By.xpath("//tr/td[@onclick='day_Click(2015,2,21);']")).click();

    driver.switchTo().defaultContent();

  • 相关阅读:
    自己搭建二维码接口
    HTML CSS SPRITE 工具
    Codeforces Round #636 (Div. 3) 题解
    Codeforces Round #612 (Div. 1+Div. 2)
    计树问题小结 version 2.0
    Educational Codeforces Round 85 (Rated for Div. 2) 题解
    luogu6078 [CEOI2004]糖果
    luogu [JSOI2012]分零食
    多项式全家桶
    生成函数小结
  • 原文地址:https://www.cnblogs.com/shuiyelifang/p/5629580.html
Copyright © 2011-2022 走看看