找到關於 Selenium WebDriver 的 190 篇文章

3K+ 次瀏覽
我們可以在 Selenium IDE 中使用 ClickAt 命令。ClickAt 命令有兩個引數 - 元素定位器和座標,該座標指出了相對於定位器標識的元素的滑鼠的 x 和 y 座標。當我們想要點選具有特定滑鼠座標的位置時,可以使用此方法。它可以點選複選框、單選按鈕或連結。語法:clickAt(locator, coordinates) 在 Selenium IDE 中,選擇測試指令碼編輯框內的行。在“命令”欄位中輸入 clickAt。要使用 id 定位器識別下拉選單,請輸入“目標”欄位。x ... 閱讀更多

2K+ 次瀏覽
我們可以使用 Selenium 進行向下滾動。Selenium 無法直接處理滾動。它藉助 Javascript 執行器來執行滾動操作到某個元素。首先,我們必須找到要滾動到的元素。接下來,我們將使用 Javascript 執行器來執行 Javascript 命令。executeScript 方法用於在 Selenium 中執行 Javascript 命令。我們將藉助 Javascript 中的 scrollIntoView 方法,並將 true 作為引數傳遞給該方法。語法:WebElement elm = driver.findElement(By.name("name")); ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", elm);示例:import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; ... 閱讀更多

543 次瀏覽
我們可以在 Selenium 中設定 Google Chrome。在設定 Chrome 瀏覽器之前,系統中應該配置 Java JDK、Eclipse 和 Selenium webdriver。設定 Google Chrome 的步驟如下:- 導航到連結:https://chromedriver.chromium.org/downloads。- 選擇與本地系統中的 Chrome 瀏覽器匹配的 Chrome 驅動程式連結。- 然後,我們必須選擇與我們正在使用的作業系統相容的 Chrome 驅動程式連結。- 將下載一個 zip 檔案。解壓縮並儲存 chromedriver.exe 檔案到某個位置。我們可以透過以下方式配置 chromedriver.exe 檔案:- 透過設定環境變數中的系統屬性。轉到 ... 閱讀更多

408 次瀏覽
我們可以使用 Selenium 模擬列印螢幕按鈕。螢幕截圖是用列印螢幕按鈕捕獲的。捕獲螢幕截圖是一個三步過程。這是故障分析中的一個重要步驟。我們將把驅動程式物件轉換為 TakeScreenshot 介面。語法:TakesScreenshot s = (TakesScreenshot)driver;然後,使用 getScreenshotAs 方法,我們將獲得一個影像檔案,並使用 FileUtils.copyFile 方法將該檔案複製到某個位置。語法:File sp=s.getScreenshotAs(OutputType.FILE); FileUtils.copyFile(sp, new File("path of image file"));示例:import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.apache.commons.io.FileUtils; import java.io.File; public class PrintScreenSimulate { public static void main(String[] args) { ... 閱讀更多

572 次瀏覽
我們可以在 Selenium 中清除瀏覽器 Cookie。deleteCookieNamed 方法將刪除具有特定名稱的 Cookie。Cookie 名稱作為引數傳遞給該方法。首先,我們將新增一個 Cookie,然後獲取它,最後刪除它。語法:driver.manage().deleteCookieNamed("foo");另一個名為 deleteAllCookies 的方法將刪除現有域中的所有 Cookie。首先,我們將新增 Cookie,然後獲取並刪除它們。語法:driver.manage().deleteAllCookies();示例:import java.util.Set; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class DeleteCookiesViaName{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); ... 閱讀更多

2K+ 次瀏覽
我們可以使用 Selenium 刪除所有域上的 Cookie。deleteAllCookies 方法用於刪除當前域中的所有 Cookie。首先,我們將新增 Cookie,然後獲取它們,最後刪除所有 Cookie。語法:driver.manage().deleteAllCookies();示例:import java.util.Set; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class DeleteCookies{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("https://tutorialspoint.tw/index.htm"); // 等待 4 秒 driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS); // 設定 Cookie 的名稱和值 ... 閱讀更多

9K+ 次瀏覽
我們可以使用 Selenium 在新標籤頁中開啟連結。。可以使用 Keys.chord 和 sendKeys 方法來實現。Keys.chord 方法允許您同時傳遞多個鍵。我們將 Keys.CONTROL 和 Keys.ENTER 作為引數傳送給 Keys.chord 方法。然後將完整的字串作為引數傳遞給 sendKeys 方法。最後,sendKeys 方法必須應用於由 driver.findElement 方法標識的連結。語法:String clicklnk = Keys.chord(Keys.CONTROL, Keys.ENTER); driver.findElement(By.xpath("//*[text()='Privacy Policy']")).sendKeys(clicklnk);示例:import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class OpenInNwTab{ public static void main(String[] args) { ... 閱讀更多

364 次瀏覽
Selenium 是一套工具,在測試社群中被廣泛使用。它無法測試桌面應用程式,只能自動化基於 Web 的測試用例。一些流行的支援的瀏覽器包括:- Firefox - Chrome - IE - Safari - Opera一些流行的支援的作業系統包括:- Linux/Unix - Mac - WindowsSelenium 受歡迎的另一個原因是它可以與不同的程式語言一起使用,例如:- Java - Python - JavaScript - Ruby - C# - PHPSelenium 的一些元件包括:- Selenium IDE - Selenium RC - Selenium WebDriver - Selenium Grid

2K+ 次瀏覽
我們可以使用 Selenium 清除文字區域的文字。我們將使用 clear 方法來移除文字區域或編輯框中的內容。首先,我們將藉助任何定位器來識別文字區域。文字區域在 HTML 程式碼中用 textarea 標籤名標識。讓我們在下面的文字區域輸入一些文字,然後清除文字。示例 import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; public class TextAreaClear{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("http://www.uitestpractice.com/Students/Form"); ... 閱讀更多