找到 190 篇文章 關於 Selenium WebDriver

3K+ 閱讀量
我們可以使用 Actions 類在 Selenium 中執行拖放操作。為了執行拖放操作,我們將使用 dragAndDrop(source, target) 方法。最後使用 build().perform() 執行所有步驟。示例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.interactions.Action; import org.openqa.selenium.interactions.Actions; import java.util.concurrent.TimeUnit; public class DrgAndDrp{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = " https://jqueryui.com/draggable/v"; driver.get(url); driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS); driver.switchTo().frame(0); WebElement ... 閱讀更多

4K+ 閱讀量
我們可以使用 Actions 類在 Selenium 中執行雙擊元素操作。為了執行雙擊操作,我們將使用 moveToElement() 方法,然後使用 doubleClick() 方法。最後使用 build().perform() 執行所有步驟。示例import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.interactions.Action; import org.openqa.selenium.interactions.Actions; import java.util.concurrent.TimeUnit; public class DoubleClick{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = "https://tutorialspoint.tw/questions/index.php"; driver.get(url); driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS); ... 閱讀更多

2K+ 閱讀量
我們可以使用 Actions 類在 Selenium 中在編輯框中輸入大寫字母。為了實現這一點,我們需要首先移動到編輯框,然後單擊該欄位。然後按 SHIFT 並使用 sendKeys() 方法輸入字母。最後使用 build().perform() 執行所有步驟。示例import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.interactions.Action; import org.openqa.selenium.interactions.Actions; import java.util.concurrent.TimeUnit; public class UpperCase{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = ... 閱讀更多

3K+ 閱讀量
我們可以使用 Actions 類在 Selenium 中執行右鍵單擊元素操作。為了執行右鍵單擊操作,我們將使用 contextClick() 方法。首先,我們需要使用 moveToElement() 方法移動到特定元素,然後使用 contextClick() 方法執行右鍵單擊。最後使用 build().perform() 執行所有步驟。示例import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.interactions.Action; import org.openqa.selenium.interactions.Actions; import java.util.concurrent.TimeUnit; public class RightClick{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); ... 閱讀更多

4K+ 閱讀量
我們可以使用 Actions 類在 Selenium 中執行滑鼠懸停元素操作。為了執行滑鼠移動操作,我們將使用 Actions 類的 moveToElement() 方法。最後使用 build().perform() 執行所有步驟。示例import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.interactions.Action; import org.openqa.selenium.interactions.Actions; import java.util.concurrent.TimeUnit; public class MouseOver{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = "https://tutorialspoint.tw/questions/index.php"; driver.get(url); driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS); // actions class ... 閱讀更多

3K+ 閱讀量
我們可以透過以下列出的方法在 Selenium 中統計 frame 的數量-使用帶有 tagname frame/iframe 的列表。使用 Javascript 執行器。示例使用 tagname。import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import java.util.List; public class FrameCount{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = "http://the-internet.herokuapp.com/nested_frames"; driver.get(url); driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS); //透過使用 frame 或 ... 閱讀更多

5K+ 閱讀量
我們可以使用以下方法在 Selenium 中切換到 frame-switchTo()defaultContent()此方法用於在 frame 和父 frame 之間進行切換。焦點將轉移到主頁面。switchTo().parentFrame()此方法用於將控制權切換到當前 frame 的父 frame。示例import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class FrameDefault { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = "包含 frame 的 url"; driver.get(url); ... 閱讀更多

6K+ 閱讀量
我們可以使用以下方法在 Selenium 中處理框架:switchTo().frame( frameNumber)此方法使用 frame id 作為引數。frame id 的索引從 0 開始。如果未找到 frame,則會丟擲 NoSuchFrameException。switchTo().frame( frameName)此方法使用開發人員定義的 frame 名稱作為引數。frame 名稱被視為字串,並用引號括起來。如果未找到 frame,則會丟擲 NoSuchFrameException。switchTo().frame( WebElement)此方法使用 webelement 作為引數。如果未找到 frame,則會丟擲 NoSuchFrameException。如果 frame 不再處於活動狀態,則會丟擲 StaleElementReferenceException。示例import org.openqa.selenium.By; ... 閱讀更多

2K+ 閱讀量
Selenium 有 getWindowHandles() 方法,它返回所有開啟視窗的所有視窗控制代碼 ID。這儲存在 String 資料型別的 Set 資料結構中。為了導航到特定視窗,我們需要使用 iterator() 方法遍歷到我們要訪問的視窗,然後切換到該視窗。getWindowHandle() 方法給出當前視窗 ID 的視窗控制代碼 ID。示例import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import java.util.List; import java.util.Set; import java.util.Iterator; import org.testng.annotations.Test; public class WindowHandles{ @Test public void windowHandle() throws Exception { ... 閱讀更多

1K+ 次檢視
Selenium WebDriver 提供多個 API 來幫助處理彈出視窗或警報,方法是使用 Alert 介面。dismiss()這將取消警報的按鈕。accept()這將接受警報的按鈕。getText()這將提取警報上的文字。sendKeys()這將在警報框中輸入文字。示例帶程式碼片段的語法 - // 警報 Alert a = driver.switchTo().alert(); // 提取警報訊息。 String msg= driver.switchTo().alert().getText(); // 在控制檯上列印訊息 System.out.println(msg); // 在警報框中輸入文字 a .sendkeys(“Testing”); // 接受警報 a.accept() // 取消警報 a.dismiss()