Tag: selenium webdriver

如何使用Geckodriver保留我的Firefox配置文件缓存?

我需要使用Selenium和Geckodriver保留我的缓存。 我有一个Firefox配置文件,我在启动Geckodriver时加载它: ProfilesIni profilesIni = new ProfilesIni(); FirefoxProfile firefoxProfile = profilesIni.getProfile(“profile-name”); firefoxOptions.setProfile(firefoxProfile); 这可以正常工作,但它不会复制缓存。 去about:cache ,它是空的。 我想保留我的缓存,我想直接使用我的个人资料。 目前, Selenium/Geckodriver复制部分配置文件并使用它,但不会使用缓存。 使用Geckodriver时如何保持缓存?

如何通过除“class”和“name”之外的属性直接查找WebElements(例如“title”)

我是Java和Selenium的新手,所以如果我的问题听起来有些重要,我会提前道歉。 我用: driverChrome.findElements(By.className(“blabla”)); 查找具有“blabla”作为其className的元素,例如: … 现在,如果我想通过其他属性查找所有元素,该怎么办? 就像是: driverChrome.findElements(By.titleValue(“the title”)); 这是我目前用于执行此任务的代码: List spans = driverChrome.findElements(By.tagName(“span”)); for (WebElement we : spans) { if (we.getAttribute(“title”) != null) { if (we.getAttribute(“title”).equals(“the title”)) { … break; } } } 但它并不快速且易于使用。

如何使用Selenium允许位置访问?

我试图在Java中使用Selenium来获取用户的地理坐标,但是使用IP地址不够准确,所以我想使用这个网站http://www.whataremycoordinates.com/ ,但它不起作用,我猜它是因为你必须允许位置使用,所以无论如何我可以允许在Selenium中使用位置,或者可能以其他方式获得精确的地理坐标

NoSuchMethodError:org.apache.http.conn.scheme.Scheme。(Ljava / lang / String; ILorg / apache / http / conn / scheme / SchemeSocketFactory;)V

我在maven项目中运行selenium测试。这个项目是GWT Web应用程序。在pom.xml中有GWT依赖项,hibernate依赖项。我在测试包中创建了一个新类来运行selenium测试用例。我还包括了selenium服务器pom.xml中的-2.33.0依赖项,但得到以下exception: – Exception in thread “main” java.lang.NoSuchMethodError: org.apache.http.conn.scheme.Scheme.(Ljava/lang/String;ILorg/apache/http/conn/scheme/SchemeSocketFactory;)V at org.openqa.selenium.remote.internal.HttpClientFactory.getClientConnectionManager(HttpClientFactory.java:59) at org.openqa.selenium.remote.internal.HttpClientFactory.(HttpClientFactory.java:48) at org.openqa.selenium.remote.HttpCommandExecutor.(HttpCommandExecutor.java:100) at org.openqa.selenium.remote.HttpCommandExecutor.(HttpCommandExecutor.java:81) at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:81) at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:244) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:110) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:188) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:183) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:179) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:92) 同时获得chrome驱动程序的例外。请指导我如何解决此问题。 我在pom.xml中使用以下依赖项: – 4.0.0 SeleniumDemo SeleniumDemo war 0.0.1-SNAPSHOT GWT Maven Archetype 2.4.0 ${project.build.directory}/${project.build.finalName} UTF-8 com.google.gwt gwt-servlet ${gwtVersion} runtime com.google.gwt gwt-user ${gwtVersion} provided <!– junit […]

使用Selenium WebDriver进行PrimeFaces fileUpload测试

我已经使用webElement.sendKeys()方法成功测试了fileUploadSimple http://www.primefaces.org/showcase/ui/fileUploadSimple.jsf 。 它不适用于自动上传 有没有办法用Selenium WebDriver测试PrimeFaces fileUploadAuto http://www.primefaces.org/showcase/ui/fileUploadAuto.jsf ?

使用GhostDriver时如何设置屏幕/窗口大小

我在基于Java的项目中使用GhostDriver作为WebDriver实现。 我想拍摄页面的快照。 默认页面大小有点笨拙,所以我想控制快照的页面大小。 但是,我找不到谷歌的任何例子。 那么,有人可以告诉我怎么样? 非常感谢你。

我为什么要使我的页面对象实例化而不是静态?

我是一名相对较新的QA工程师,致力于学习Selenium(Java),我想使用页面对象来模拟我的页面。 目前,我正在这样做,我的页面对象类是静态变量(用于定位页面元素的对象)和静态方法(用于获取By对象和执行页面函数)的集合。 这对我来说似乎是最简单的方法,因为我的方法不需要依赖任何实例变量,只需要依赖定位器。 我只是在我的测试代码中调用这些方法。 但是,我读到的关于页面对象的所有内容都涉及实例化它们并让方法返回页面对象。 这似乎使一切变得更加复杂。 例如,我没有一个登录方法,而是需要两个,一个用于登录成功,一个用于登录失败。 我知道它似乎是公认的最佳实践,但我想了解原因。 谢谢。 这是我的pageObject代码,我的测试调用方法为LoginPage.login(username, password); package pageObjects; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; public class LogInPage { private static By emailTxtB = By.id(“user_email”); private static By passwordTxtB = By.id(“user_password”); private static By logInButton = By.xpath(“/html/body/div/div[2]/form/div[2]/div[2]/div/button”); private static By signUpButton = By.xpath(“/html/body/div/div[2]/form/div[2]/div[2]/div/a”); private static By valErrorMessage = By.id(“flash_alert”); public static void logIn(WebDriver […]

selenium exceptionin java(org.openqa.selenium.remote.UnreachableBrowserException)

我知道有多少线程正在运行,但没有一个解决这个问题。 我正在尝试使用selenum获取aspx页面。 但它在这行代码中抛出UnreachableBrowserException WebDriver driver = new ChromeDriver(); 。 chrome的一个实例正在打开,但之后几秒钟就会抛出我上面提到的exception。 这是我的示例代码。 System.setProperty(“webdriver.chrome.driver”, “C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe”); WebDriver driver = new ChromeDriver(); driver.get(“http://some aspx page with form”); System.out.println(“!!!!! Got the page !!!!!”); driver.close(); driver.quit(); 以下是堆栈跟踪。 Exception in thread “main” org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser […]

Selenium WebDriver – getCssValue()方法

我正在练习使用cssGetValue方法从特定Web元素的CSS属性中检索值。 我有两个问题: 为什么cssGetValue方法返回值13px,哪个web元素执行实际引用的方法。 1A。 我想获得标记为“By ID”的部分的CSS属性。 我应该如何修改我的代码,以便我可以获得id =“by-id”部分的CSS属性值? 我使用了driver.close()方法,但是在脚本完成后它不会关闭浏览器。 请解释为什么在这种情况下driver.close()方法不起作用。 这是我的代码片段: package wd_findElementBy; import java.util.List; import org.junit.Test; import org.junit.Before; import org.junit.After; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; public class SearchWebElements { WebDriver driver = new FirefoxDriver(); private String baseUrl= “http://docs.seleniumhq.org/docs/03_webdriver.jsp#introducing-the-selenium-webdriver-api-by-example”; @Test public void findElements(){ driver.get(baseUrl); try{ List elements = driver.findElements(By.id(“by-id”)); System.out.println(“number of elements: […]

在selenium网格上创建并上传文件

我的一个测试用例是将文件上传到应用程序。 通过创建伪造文件并获取文件的绝对路径并填充输入字段并单击上载,可以轻松完成Witouth网格。 但是,当我使用网格时,该文件不在托管节点的计算机上。 无论如何要么将文件发送到节点或告诉节点创建文件并获取绝对路径。