當前位置:編程學習大全網 - 源碼下載 - 急急急,java模擬用戶行為,字文本輸入內容後,點擊提交,獲取最終顯示的頁面,webdriver,

急急急,java模擬用戶行為,字文本輸入內容後,點擊提交,獲取最終顯示的頁面,webdriver,

package main;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.ie.InternetExplorerDriver;

import org.openqa.selenium.support.ui.ExpectedCondition;

import org.openqa.selenium.support.ui.WebDriverWait;

public class Test {

public static void main(String[] args){

//創建壹個WebDriver實例

System.setProperty("webdriver.ie.driver", "Driver\\IEDriverServer.exe");

WebDriver driver= new InternetExplorerDriver();

//訪問百度

driver.get("www.baidu.com");

//另壹種方式

driver.navigate().to("www.google.com");

//找到文本框

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

//搜索關鍵字

element.sendKeys("selenium");

//提交表單 webDriver會自動從表單中查找提交按鈕並提交

element.submit();

//檢查頁面title

System.out.println("頁面Title:"+driver.getTitle());

//設置等待時間為10秒

(new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {

@Override

public Boolean apply(WebDriver d) {

// TODO Auto-generated method stub

return d.getTitle().toLowerCase().startsWith("selenium");

}

});

// 顯示查詢結果title

System.out.println("Page title is: " + driver.getTitle());

//關閉瀏覽器

driver.quit();

}

}

  • 上一篇:怎樣找到linux下mysql安裝目錄並改變安裝目錄
  • 下一篇:阿修羅基石源代碼
  • copyright 2024編程學習大全網