最近在學習selenium基於java的自動化測試腳本的編寫,遇到很多問題,打算開帖記錄一下,年級大了,記性不好。
1. 下拉菜單內容的獲取:
Select userSelect=new Select(driver.findElement(By.xpath(".//*[@id='fixed_left_id']/div/common-sensoradd/div[1]/div/div/div[4]/div[2]/div[1]/select")));
userSelect.selectByVisibleText("溫度");
2. 獲得輸入框內容並與字符串比較:
JavascriptExecutor js = (JavascriptExecutor) driver;
String value = (String)js.executeScript("return arguments[0].value;",input);
System.out.println(value);
Select userSelect2=new Select(driver.findElement(By.xpath(".//*[@id='alterList_device_type_id']")));
if(value.equals("室內溫度")){
userSelect2.selectByVisibleText("環境溫度");
}
3. 鼠標滾動到頁面最底部:
JavascriptExecutor driver_js= (JavascriptExecutor) driver;
driver_js.executeScript("window.scrollTo(0,document.body.scrollHeight)");
4. HTML5新特性--使用<video>播放視頻:
播放暫停可控制:
<!DOCTYPE html>
<html>
<head>
<title>HTML5-video</title>
</head>
<body>
<video width="320" height="240" controls="controls">
<source src="E:/selenium/aaa.mp4" type="video/mp4">
您的瀏覽器不支持 video 屬性。
</video>
</body>
</html>
自動播放:
<!DOCTYPE html>
<html>
<head>
<title>HTML5-video</title>
</head>
<body>
<video width="320" height="240" controls autoplay>
<source src="E:/selenium/aaa.mp4" type="video/mp4">
您的瀏覽器不支持 video 屬性。
</video>
</body>
</html>