Tag: selenium webdriver

如何修复NoClassDefFoundError:CircularOutputStream错误?

我只是为Selenium WebDriver(又名Selenium 2)为无头测试创建了一个简单的maven项目。 我在pom.xml中添加了PhantomJS驱动程序依赖项和其他依赖项: com.github.detro phantomjsdriver 1.2.0 但它得到了错误: java.lang.NoClassDefFoundError: org/openqa/selenium/io/CircularOutputStream at org.openqa.selenium.firefox.FirefoxBinary.(FirefoxBinary.java:60) at org.openqa.selenium.firefox.FirefoxBinary.(FirefoxBinary.java:56) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:120) at jp.co.skygate.home.HomePageLogin.setUp(HomePageLogin.java:108) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at 只是从pom.xml中删除PhantomJS依赖项解决了问题并且执行正常。 有人能帮我找到问题吗? 提前致谢。

来自Selenium 2 / WebDriver的Id的jQuery元素选择器

我可以在Selenium中使用((RemoteWebElement) webElement).getId()获取元素的ID,它返回如下字符串: {e9b6a1cc-bb6f-4740-b9cb-b83c1569d96d} 我想知道该ID的来源。 我正在使用FirefoxDriver() ,所以这个Firefox有关吗? 有没有办法只通过知道这个ID来选择一个带有Jquery的元素?

Selenium WebDriver – 意外的modal dialog警报

我正在尝试使用WebDriver来自动化网站。 我正在使用Firefox驱动程序,但主页有一个弹出模式警报窗口:说: 您需要使用IE 6.0查看此应用程序。 否则一些function可能无法正常工作我检查了页面的来源,它有一个function。 模态警报不是HTML元素,我尝试使用FireBug查找任何元素,但无济于事。 if ( strBrowName == “Microsoft Internet Explorer” ) { if ( (( strBrowVersion.indexOf( ‘MSIE 6’ ) ) > 0 ) ) { } else { alert( “You need to use IE 6.0 for viewing this application. Else some features may not work” ); } 在我的WebDriver代码中,我在驱动程序中使用了以下function(如此处的其他post所示) DesiredCapabilities dc=new DesiredCapabilities(); dc.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR,UnexpectedAlertBehaviour.ACCEPT); […]

如果测试用例失败,Selenium Web驱动程序无法关闭firefox实例

我大家,我正在使用junit与selenium web驱动程序2.28。 问题是如果我运行一个成功的测试用例,web驱动器能够关闭firefox实例,但是当测试用例失败时,selenium web驱动程序无法关闭firefox。 我正在使用FF 15.0.1与selenium-server-standalone-2.28.0.jar。 请回复谢谢Sahil private void startWebdriver() throws UIException{ //2) Prevent re-use. if(UIHandlerWD.this.profile == null) throw new UIException( UIException.Code.UI, “Webdriver instance cannot be instantiated.” ); //3) Configure Selenium Webdriver. if (this.profile.browserType.equalsIgnoreCase(“*firefox”)){ FirefoxProfile fProfile = new FirefoxProfile(); // profile.SetPreference(“network.http.phishy-userpass-length”, 255); fProfile.setAcceptUntrustedCertificates(true); DesiredCapabilities dc = DesiredCapabilities.firefox(); dc.setJavascriptEnabled(true); dc.setCapability(FirefoxDriver.PROFILE, fProfile); //this.webdriver = new FirefoxDriver(dc); this.webdriver […]

使用Java中的Selenium快速获取每个WebElement的class属性

我希望用selenium快速获取页面上每个WebElement的class属性。 目前,我正在做以下事情: allElements = new ArrayList(m_webDriver.findElements(By.cssSelector(“*”))); for (WebElement element : allElements) { String className = element.getAttribute(“class”); } 这个过程非常慢,在包含500个元素的页面上花费超过30秒。 我尝试并行化getAttribute调用,这是该方法中最慢的部分,但没有速度增加。 这让我相信每次调用getAttribute都是获取信息而不是在本地存储信息。 有没有更快或可并行的方式来做到这一点?

Selenium没有在IE中检测到第二个窗口

我的应用程序打开了一个单击按钮的新窗口,我需要在该窗口中执行一些操作。 但是selenium webdriver的响应getWindowHandles()方法只有一个窗口id。 如果在打开新窗口后调用getWindowHandles()有延迟,则会发生这种情况。 selenium存在已知问题。 https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration 但即使是解决方案也不适用于我。 代码如下 DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); RemoteWebDriver driver = new RemoteWebDriver(new URL(“http://localhost:4444/wd/hub”), capabilities); driver.get(“https://”); WebElement userName = driver.findElement(By.name(“usr_name”)); userName.sendKeys(“ABCD”); WebElement password = driver.findElement(By.name(“usr_password”)); password.sendKeys(“password”); WebElement login = driver.findElement(By.name(“OK”)); login.click(); WebElement popup= driver.findElement(By.name(“popup”)); popup.click(); Thread.sleep(1000); Set windowHandles = driver.getWindowHandles(); System.out.println(windowHandles); Set“ windowHandles ”将只返回一个窗口: “[fcdad457-9090-4dfd-8da1-acb9d6f73f74]” 但如果我取消睡眠。 它将返回两个窗口ID: [90cc6006-0679-450c-a5b3-6602bcb41a16, 7211bbfd-2616-4460-97e7-56c0e632c3bb] 我无法移除睡眠,因为这只是一个示例程序,在实际应用程序中,它们之间会有一些延迟。 请让我知道你的想法。 […]

Selenium 2:中断页面加载

单击带有Firefox驱动程序的Selenium 2.0b3 Java API的按钮时出现问题。 单击该按钮会将表单发送到Web服务器,然后由于表单提交,浏览器将转到新页面。 当使用element.click()单击元素时,selenium正在等待浏览器完成其操作。 浏览器等待页面加载完成。 但是,由于某些广告请求,有时页面加载会花费大量时间。 如何解决element.click()和页面加载之间的同步问题? 编辑: 正如WebElement javadoc中所解释的那样: 单击此元素。 如果这导致加载新页面,则此方法将阻止,直到页面加载为止。 谢谢

如何使用selenium设置“value”来输入web元素?

我的代码中的元素看起来像这样: 我想设置它的值,所以我用它的xpath创建了一个web元素: val test = driver.findElements(By.xpath(“””//*[@id=”invoice_supplier_id”]”””)) 但现在我没有看到设置值的选项……

action.sendKeys(body,Keys.CONTROL +“j”)不要打开下载页面

我正在使用Java和Selenium为Chrome编写测试。 我需要在某一点打开下载页面,所以我使用了: action.sendKeys(Keys.CONTROL + “j”).build().perform(); 但它不会打开页面。 然后我在它之前添加了这一行,因为我虽然它可能有效,但它没有: WebElement body = wait.until(ExpectedConditions.elementToBeClickable(By.xpath(“//body[@id=’body’]”))); action.sendKeys(body, Keys.CONTROL + “j”).build().perform(); 奇怪的是 action.sendKeys(Keys.CONTROL + “a”).build().perform(); 作品!! 注意:我不想使用Robot类,因为如果焦点不在测试目标浏览器上,它将在其他浏览器上打开页面。

使用testng中的DataProvider从文件中读取数据

假设我有一个包含以下数据的文本文件 username=testuser password=testpassword email=test@test.com address=testaddress zipcode=12345 或者我有一个包含以下数据的XML testuser testpassword test@test.com testaddress 我有一个测试如下 public class DPTest { @Test(dataprovider=”testdp”) public void userTest_01(String username, String Password) { //Test goes here } } 另一堂课 public class DPTest2 { @Test(dataprovider=”testdp”) public void userTest_02(String email, String address, String password) { //Test goes here } } 我的dataprovider可以读取上面提到的文本文件或XML中的值并将其提供给测试方法吗? 根据我的理解,数据提供程序将读取文本文件中的所有行并将其提供给测试方法,并抛出错误说“数据提供程序正在尝试提供6个参数,但测试只能接受2个参数”? 请帮帮我。