找到关于 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.com/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"); ... 阅读更多
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP