亚洲好骚综合-亚洲黄色录像-亚洲黄色网址-亚洲黄色网址大全-99久久99久久-99久久99久久精品国产

您的位置:軟件測(cè)試 > 開源軟件測(cè)試 > 開源功能測(cè)試工具 > Selenium
Selenium webdriver操作日歷控件
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2015/2/2 16:15:42 ] 推薦標(biāo)簽:Selenium 功能測(cè)試工具

  一般的日期控件都是input標(biāo)簽下彈出來的,如果使用webdriver 去設(shè)置日期,
  1. 定位到該input
  2. 使用sendKeys 方法
  比如:

  但是,有的日期控件是readonly的
  比如12306的這個(gè)
  <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">
  這個(gè)時(shí)候,沒法調(diào)用WebElement的sendKeys()
  方案一:使用JS remove readonly attribute,然后sendKeys
  還是以萬惡的12306為例:
  使用出發(fā)日期,將input標(biāo)簽的readonly熟悉去掉
  JavascriptExecutor removeAttribute = (JavascriptExecutor)driver;
  //remove readonly attribute
  removeAttribute.executeScript("var setDate=document.getElementById("train_date");setDate.removeAttribute('readonly');") ;
  方案二:采用click直接選擇日期,日期控件是一個(gè)iframe,首先switch iframe,之后找到想要設(shè)置的日期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();
  具體代碼如下:
WebDriver driver=DriverFactory.getFirefoxDriver();
driver.get("https://kyfw.12306.cn/otn/");
driver.manage().window().maximize();
driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
WebElement fromStation=driver.findElement(By.xpath("//input[@id='fromStationText']"));
fromStation.click();
fromStation.sendKeys("鄭州");
WebElement choseFrom =driver.findElement(By.xpath("//div/span[@class='ralign' and text()='鄭州']"));
choseFrom.click();
WebElement toStation=driver.findElement(By.xpath("//input[@id='toStationText']"));
toStation.click();
toStation.sendKeys("上海");
WebElement choseElement =driver.findElement(By.xpath("//div/span[@class='ralign' and text()='上海']"));
choseElement.click();
JavascriptExecutor removeAttribute = (JavascriptExecutor)driver;
//remove readonly attribute
removeAttribute.executeScript("var setDate=document.getElementById("train_date");setDate.removeAttribute('readonly');") ;
WebElement setDatElement=driver.findElement(By.xpath("//input[@id='train_date']"));
setDatElement.clear();
setDatElement.sendKeys("2015-02-18");
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();
WebElement searchElement=driver.findElement(By.xpath("//div/a[@id='a_search_ticket']"));
searchElement.click();

上一頁12下一頁
軟件測(cè)試工具 | 聯(lián)系我們 | 投訴建議 | 誠(chéng)聘英才 | 申請(qǐng)使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd
主站蜘蛛池模板: 日韩精品国产自在久久现线拍 | 波多野结衣久久国产精品 | 美国一级大黄一片免费的网站 | 国产一卡二卡三卡 | 久久精品视频免费 | 无遮羞肉动漫在线观看免费 | 亚洲日本va午夜中文字幕 | 欧美一级特黄高清免费 | 最新国产午夜精品视频不卡 | 一级看片免费视频 | 韩日在线视频 | 91精品国产一区二区三区左线 | 午夜国产福利 | 美女视频永久黄网站免费观看国产 | 亚洲无线观看 | 一级在线 | 欧洲 | 日本一本在线视频 | 日韩伦理中文字幕 | 国产精品亚洲第五区在线 | 怡红院在线视频精品观看 | 亚洲高清视频在线观看 | 国产高清免费在线观看 | 麻豆回家视频区一区二 | 亚洲最大在线视频 | 天天澡夜夜澡狠狠澡 | 中文字幕一区在线观看 | 精品国产免费第一区二区 | 日本久久久久久久中文字幕 | 日本欧美久久久久免费播放网 | 成人资源在线观看 | 一区二区三区波多野结衣 | 免费在线h视频 | 国产观看精品一区二区三区 | 天天射天天爽 | 国产成人免费在线视频 | 一本大道高清香蕉中文大在线 | 亚洲精品乱码中文字幕无线 | 亚洲第一区视频在线观看 | 久久综合五月 | 1024手机基地在线观看 | 欧美日本中文字幕 |