Tag: selenium webdriver

ChromeDriver:自定义Chrome可执行文件路径

我正在使用便携版Google Chrome。 由于WebDriver需要默认安​​装路径,因此它找不到显然位于其他位置的便携式路径: Exception in thread “main” org.openqa.selenium.WebDriverException: unknown error: cannot find Chrome binary (Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 11.13 seconds Build info: version: ‘2.35.0’, revision: ‘8df0c6b’, time: ‘2013-08-12 15:43:19’ System info: os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: […]

我应该如何最好地与Selenium Java WebDriver中的Flash进行交互

我知道一些类似的问题,例如( 使用WebDriver的Interact flash元素 )过去曾被问过,但是仍然不清楚如何最好地与Selenium的Java WebDriver相关联的页面上的Flash元素进行交互。 默认情况下,我知道它不支持Flash,所以我用它来登录网站,这很好。 现在我需要与flash元素进行交互,如本页所示: http://store.nike.com/us/en_us/product/free-tr-4-id/?piid=34979&pbid=517639039 我希望能够从页面左侧的Flash中选择一个鞋码,然后单击“添加到购物车”按钮。 任何达成此目标的人都能以最好的方式提供他们的指导和意见。 我尝试过https://code.google.com/p/flash-selenium/,但这似乎是旧的,或与新的Java WebDriver不兼容。

带有not()和ends-with()的Xpath错误

我有以下Xpath表达式: //*[not(input)][ends-with(@*, ‘Copyright’)] 我希望它能给我所有元素 – 输入除外 – 任何以“Copyright”结尾的属性值。 我使用webDriver.findElements(By.xpath(expression))在Selenium 2 Java API中执行它并获得以下错误: 表达式不是法律表达 但这些表达没有问题: //*[not(input)][starts-with(@*, ‘Copyright’)] //*[ends-with(@*, ‘Copyright’)] 有任何想法吗?

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类,我无法在上面的场景中使用它。 […]

绑定不匹配错误和javagenerics方法

我收到以下错误: Bound mismatch: The generic method constructPage(WebDriver, int, Class) of type Page is not applicable for the arguments (WebDriver, int, Class). The inferred type HomePage is not a valid substitute for the bounded parameter <T extends Page> 我正在尝试登录并返回主页,如果成功,则返回LoginPage,如果不使用generics。 我有一个基类,Page由SecuredPage扩展,用于登录墙后面的页面。 我编写了一个通用的辅助方法来构造任何类型的页面。 LoginPage上的登录方法使用此方法。 LoginPage扩展页面和HomePage扩展SecuredPage。 SecuredPage扩展了Page。 如果返回LoginPage,则登录方法有效,但是在尝试返回HomePage时出现上述错误。 由于HomePage是页面的子类,因为它的父类扩展了Page,所以我很困惑为什么HomePage不能有效替代有界参数<T extends Page> 。 public abstract class Page<T extends Page> extends […]

额外的记录JBehave

场景是这样的: 我们使用JBehave和Selenium进行系统,集成和端到端测试。 我正在检查超过20个值的页面上的计算结果以进行validation。 使用Junit断言整个测试将在其中一个值不正确的第一个实例上失败。 我想要做的是,如果一个断言失败,那么测试继续执行,这样我就可以在一次测试运行中整理所有不正确的值,而不是多次测试运行。 为此,我捕获断言并将未通过validation的任何内容写出到日志文件中。 这给我留下了几个问题: 1)我写出断言失败的日志文件不包含发生exception时正在运行的JBehave Story或Scenario的名称。 2)JBehave Story或Scenario被列为’通过’,我希望它被列为’失败’。 有没有办法可以将Story和Scenario的名称记录到附加日志文件中,或者将其他日志记录写入JBehave日志文件? 如何将Story / Scenario标记为失败? 在JBehave配置中,我有: configuredEmbedder() .embedderControls() .doIgnoreFailureInStories(true) .doIgnoreFailureInView(false) .doVerboseFailures(true) .useStoryTimeoutInSecs(appSet.getMaxRunningTime()); 和 .useStoryReporterBuilder( new StoryReporterBuilder() .withDefaultFormats() .withViewResources(viewResources) .withFormats(Format.HTML, Format.CONSOLE) .withFailureTrace(true) .withFailureTraceCompression(true) .withRelativeDirectory(“jbehave/” + appSet.getApplication())

使用多个条件在Selenium中查找WebElement

我正在使用Selenium来测试一个网站,如果我通过多个标准查找和元素,这是否有效? 例如 : driverChrome.findElements(By.tagName(“input”).id(“id_Start”)); 要么 driverChrome.findElements(By.tagName(“input”).id(“id_Start”).className(“blabla”));

如何等待Selenium中的元素不再存在

我正在测试用户单击删除按钮的UI,表条目消失。 因此,我希望能够检查表条目不再存在。 我已经尝试使用ExpectedConditions.not()来反转ExpectedConditions.presenceOfElementLocated() ,希望它意味着“期望不存在指定的元素”。 我的代码是这样的: browser.navigate().to(“http://stackoverflow.com”); new WebDriverWait(browser, 1).until( ExpectedConditions.not( ExpectedConditions.presenceOfElementLocated(By.id(“foo”)))); 但是,我发现即使这样做,我得到一个由NoSuchElementException引起的TimeoutExpcetion ,说元素“foo”不存在。 当然,没有这样的元素是我想要的,但我不想抛出exception。 那么我怎么能等到一个元素不再存在呢? 我更喜欢一个不依赖于捕获exception的示例(如我所知),exception应该抛出exception行为。

如何在Selenium中测试“记住我”复选框function

我正在尝试测试登录表单的“记住我”function。 我可以输入用户名和密码,单击复选框,单击“提交”,然后quit()或close()浏览器。 但是当我使用new ChromeDriver() (或任何其他WebDriver实现)重新打开浏览器时,测试站点不会记住任何内容,因为在浏览器关闭时会删除所有cookie,并且在重新打开浏览器时无法访问它们。

如何使用Selenium WebDriver和Java在同一浏览器中打开新选项卡?

我可以使用Java和JavaScript在Selenium WebDriver上打开一个新窗口。 我正在使用Firefox。 代码如下: WebDriver driver = new FirefoxDriver(); JavascriptExecutor jse = (JavascriptExecutor)driver; jse.executeScript(“function createDoc(){var w = window.open(); w.document.open(); w.document.write(‘Hello World!’); w.document.close();}; createDoc();”); 如何使用WebDriver(Selenium 2)在同一浏览器中打开新选项卡?