Tag: webdriver

Selenium 2 chrome驱动程序首选项java相当于RubyBindings

我一直在寻找一种方法来设置过去两天使用java的Chrome驱动程序的驱动程序首选项,但没有运气。 然而,我在ruby VIA RubyBindings中找到了一个解决方案,并且想知道是否有一个我可以使用的java等效行。 ruby代码如下: profile = Selenium::WebDriver::Chrome::Profile.new profile[‘download.prompt_for_download’] = false profile[‘download.default_directory’] = “/path/to/dir” driver = Selenium::WebDriver.for :chrome, :profile => profile 在搜索时我发现chrome没有我可以像FirefoxProfile类那样使用的探查器,所以我开始使用DesireCapabilities类。 在对此问题进行进一步调查后,我发现我可以设置“开关”和“prefs”VIAfunction。设置可用性并最终得到以下结果: Map prefs = new Hashtable(); prefs.put(“download.prompt_for_download”, “false”); prefs.put(“download.default_directory”, “/path/to/dir”); prefs.put(“download.extensions_to_open”, “pdf”); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability(“chrome.prefs”, prefs); dr = new ChromeDriver(capabilities); 但是我无法使其正常工作,默认下载目录在启动后从未更改为指定目录。 我不确定我是如何设置此function的问题,或者问题是否存在于其他地方。 最后我最终使用了这里提出的解决方案: http://dkage.wordpress.com/2012/03/10/mid-air-trick-make-selenium-download-files/ 但我想知道是否可以更干净地做到这一点,但只是直接设置首选项而不是使用UI 任何帮助表示赞赏,谢谢! 更新: 令人惊讶的是,在将Selenium 2更新到版本2.24.1(以及windows chrome 22)后,上面的代码与Maps按预期工作,现在唯一的问题是他们不赞成使用构造函数ChromeDriver(DesiredCapabilitiesfunction),而是建议我使用ChromeOptions类,我无法在上面的场景中使用它。 […]

Selenium Webdriver:使用相对于其他元素的路径进行页面工厂初始化?

我正在尝试使用页面工厂@FindBy注释在Selenium Webdriver中编写页面对象。 页面对象用于侧边栏,包含页面对象需要与之交互的所有元素的父WebElement以这种方式初始化: @FindBy (xpath = “//div[contains(@class,’yui3-accordion-panel-content’) and child::div[.=’Sidebar’]]”) WebElement sidebar; 然后我想要相对于这个sidebar元素的搜索输入。 有没有办法做这个引用sidebar元素? 我可以将整个路径复制并粘贴到开头: @FindBy (xpath = “//div[contains(@class,’yui3-accordion-panel-content’) and child::div[.=’Sidebar’]]//input[@id=’search’]”) 但我宁愿相对于第一个元素。 这样的事情可能吗? @FindBy (parent = “sidebar”, xpath = “.//input[@id=’search’]”) 关于@FindBy注释的Selenium文档有点缺乏……

如何配置selenium webdriver以使用自定义firefox设置进行测试?

我正在使用Ubuntu 11.04和selenium 2.9.0以下是我在root pom中的配置方式: org.seleniumhq.selenium selenium-java 2.9.0 test 在准备运行测试时,我得到一个例外: org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output: *** LOG addons.xpi: startup *** LOG addons.xpi: Ignoring file entry whose name is not a valid add-on ID: > /tmp/anonymous3804893394247066972webdriver-profile/extensions/webdriver-staging *** LOG addons.xpi: checkForChanges *** LOG addons.xpi: No changes found […]

Webdriver:java.net.BindException:地址已在使用中:connect

在运行webdriver时,运行3分钟后,我收到以下exception并且Webdriver崩溃。 我只使用一个webdriver实例和一个FirefoxDriver配置文件。 Exception in thread “main” org.openqa.selenium.WebDriverException: java.net.BindException: Address already in use: connect System info: os.name: ‘Windows XP’, os.arch: ‘x86’, os.version: ‘5.1’, java.version: ‘1.6.0_18’ Driver info: driver.version: remote at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java: 341) at org.openqa.selenium.firefox.FirefoxDriver.execute(FirefoxDriver.java: 234) at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java: 173) at org.openqa.selenium.remote.RemoteWebDriver.findElementsByXPath(RemoteWebDriver.java: 231) at org.openqa.selenium.By$6.findElements(By.java:200) at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java: 158) Caused by: java.net.BindException: Address already in use: connect at java.net.PlainSocketImpl.socketConnect(Native […]

driver.wait()抛出IllegalMonitorStateException

wait(…)的所有变体都从以下代码中抛出以下exception。 我究竟做错了什么? java.lang.IllegalMonitorStateException at java.lang.Object.wait(Native Method) at java.lang.Object.wait(Object.java:485) at LoginPage.main(LoginPage.java:29) try { driver.get(“http://domain:port/coco/webapp/login/login.faces”); driver.findElement(By.id(“clientCode”)).sendKeys(“coco”); driver.findElement(By.id(“systemCode”)).sendKeys(“consumer”); driver.findElement(By.id(“userId”)).sendKeys(“ffadmin”); driver.findElement(By.id(“password”)).sendKeys(“password”); driver.findElement(By.className(“af_commandButton”)).click(); driver.wait(); Assert.assertTrue(driver.getPageSource().contains(“Administration”)); } catch (Exception e) { e.printStackTrace(); }

Webdriver findElements由xpath

1)我正在做一个教程来展示findElements by xpath是如何工作的。 我想知道为什么它返回属于id=container的 元素之后的所有文本。 xpath的代码: By.xpath(“//div[@id=’container’] 2)我应该如何修改代码,以便它只返回跟随父笔记的第一个或前几个节点,例如第一个节点,如“Home”,首先是几个节点,如Home,Manual Testing和Automation Testing。 感谢您的建议和帮助! 以下是本教程的代码片段: 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 WD_findElements { @Test public void test_byxpath(){ WebDriver driver = new FirefoxDriver(); try{ driver.get(“http://www.hexbytes.com”); List elements = driver.findElements(By.xpath(“//div[@id=’container’]”)); System.out.println(“Test7 number of elements: ” + elements.size()); for(WebElement […]

Selenium在一台计算机上发生了“UnreachableBrowserException / Address has in use”

我有一个java webdriver驱动的selenium执行,它在列表上循环,在文本框中输入不同的信息并使用FirefoxDriver发送它。 在一台计算机上,在第10次或第11次迭代之后,相当可重现,调用findElement(By.id(“mi4”))会引发UnreachableBrowserException 。 Jun 29, 2012 1:52:02 PM org.apache.http.impl.client.DefaultRequestDirector tryConnect Information: I/O exception (java.net.BindException) caught when connecting to the target host: Address already in use: connect Jun 29, 2012 1:52:02 PM org.apache.http.impl.client.DefaultRequestDirector tryConnect Information: Retrying connect Jun 29, 2012 1:52:02 PM org.apache.http.impl.client.DefaultRequestDirector tryConnect Information: I/O exception (java.net.BindException) caught when connecting to the target host: […]

将选项传递给chrome驱动程序selenium

我试图禁用输出到控制台的chrome。 如果我通过–start-maximized选项,它可以正常工作。 我可能有错误的命令? DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability(“chrome.switches”, Arrays.asList(“–silent”)); chrome = new ChromeDriver(_chromeservice,capabilities); 我也试过了 ChromeOptions options = new ChromeOptions(); options.addArguments(“silent”); chrome = new ChromeDriver(options); 产量 已启动ChromeDriver port = 26703 version = 23.0.1240.0 log = / Brett / workspace / TestNG / chromedriver.log [1214/161331:ERROR:ipc_sync_channel.cc(378)]取消待处理的发送[1214/161331:错误:ipc_sync_channel.cc( 378)]取消待处理的发送[1214/161331:错误:ipc_sync_channel.cc(378)]取消待处理的sendBlockquote

无法为Selenium / WebDriver运行Java示例

在Java上使用Selenium时遇到问题。 我正在尝试按照此页面上的示例操作: http : //code.google.com/p/selenium/wiki/GettingStarted 我正在打字: $ javac -cp . -cp ~/Downloads/selenium-2.20.0/selenium-java-2.20.0-srcs.jar -cp ~/Downloads/selenium-2.20.0/selenium-java-2.20.0.jar -g Example.java 得到这个: alis-mac-pro:selenium ali$ java ExampleException in thread “main” java.lang.NoClassDefFoundError: Example (wrong name: org/openqa/selenium/example/Example) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631) at java.lang.ClassLoader.defineClass(ClassLoader.java:615) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) at java.net.URLClassLoader.defineClass(URLClassLoader.java:283) at java.net.URLClassLoader.access$000(URLClassLoader.java:58) at java.net.URLClassLoader$1.run(URLClassLoader.java:197) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) […]

如何使用Selenium WebDrivervalidation元素中是否存在属性?

我的屏幕上有很多单选按钮。 选择单选按钮时,它具有已检查的属性。 未选择单选按钮时,不存在checked属性。 我想创建一个方法,如果元素不存在将通过。 我正在使用selenium webdriver和java。 我知道我可以使用getSingleElement(XXX).getAttribute(XXX)来检索属性。 我只是不确定如何validation属性不存在,以及测试在不存在时传递(如果确实存在则失败)。 选中单选按钮时 未选中单选按钮时 我希望在checked属性不存在时传递测试