Tag: selenium webdriver

无法在IE上运行Selenium脚本

我要在IE 10浏览器上运行Selenium测试。 为了运行以下脚本,我做了以下事情: 从这里下载了IEDriverServer(64位,因为我的机器是64位) 将该(.exe)文件放在“C:// drivers”文件夹中 在环境变量中设置路径’C:// drivers’ 运行脚本 require ‘selenium-webdriver’ driver = Selenium::WebDriver.for :ie driver.get “http://www.google.com” button = driver.find_element(:id, “gbqfba”) puts button.text driver.quit 将aboe脚本结果运行到以下错误中: c:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/response.rb:51:in `assert_ok’: Unable to find element with id == gbq fba (Selenium::WebDriver::Error::NoSuchElementError) from c:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/response.rb:15:in `initialize’ from c:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/http/common.rb:59:in `new’ from c:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/http/common.rb:59:in `create_response’ from c:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/http/default.rb:66:in `request’ from c:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/http/common.rb:40:in `call’ from c:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.33.0/lib/selenium/webdriver/remote/bridge.rb:629:in `raw_execute’ […]

使用Capybara / Selenium Webdriver测试HTML5文件上传 – Ruby

我有一个简单的模态,其中显示用户显示浏览按钮以添加要上载的文件。 由于一个未知的问题,因此它是一个HTML5文件输入因此浏览器添加自己的function,这已成为一个痛苦的测试。 在我的页面上,我有: Capybara提供开箱即用的解决方案: attach_file <>, <> 在幕后执行send_keys命令将file_path推送到此输入的路径容器中,但是这对我的设置无效。 我在Windows 8上运行Firefox 25.0.1。我尝试了相对路径和该文件的完整路径,包括前向和反斜杠组合。 当我的意思是它不起作用时,我的意思是当我的ajax脚本通过点击旁边的“上传”按钮执行时,它不会在参数中发送任何文件对象。 我甚至尝试使用capybara直接发送文件路径: find_field(<>).native.send_keys(<>) 接下来,是尝试使用selenium将其推入使用: element = driver.find_element(:id, <>) element.send_keys <> 然后我尝试执行脚本以确保元素可见,然后设置它: element = page.execute_script( “document.getElementById(‘#{<>}’).style.visibility = ‘visible’; document.getElementById(‘#{<>}’).style.height = ’20px’; document.getElementById(‘#{<>}’).style.width = ’60px’; document.getElementById(‘#{<>}’).style.opacity = 1; return document.getElementById(‘#{<>}’)”) find_field(field_locator).native.send_keys(<>) 这也不起作用。 现在我完全卡住了。 所有这里的帮助和谷歌指向使用上述,但它只是不适用于我的设置。 我可以看到我的选择是使用Windows自动化脚本并跳出水豚,运行脚本,然后继续,或者直接从capybara使用post调用上传URL或调用当前的js ajax可以。

如何在执行操作之前让Selenium / Ruby bot等待?

我正在构建一个点击元素的Selenium / Ruby Web机器人。 问题是,在僵尸程序决定无法找到该元素之前,有时没有足够的时间加载页面。 在执行操作之前让Selenium等待的Ruby方法是什么? 我更喜欢明确的等待,但我也很好地隐瞒等待。 我试着使用wait.until方法: require “selenium-webdriver” require “nokogiri” driver = Selenium::WebDriver.for :chrome wait = Selenium::WebDriver::Wait.new(:timeout => 15) driver.navigate.to “http://google.com” driver.wait.until.find_element(:class, “gb_P”).click 但是我收到以下错误: Undefined method ‘wait’ for 我也尝试过: require “watir-webdriver/wait” … driver.find_element(:class, “gb_P”).wait_until.click 但这也给了我一个未定义的方法错误: undefined method `when_present’ for #

Selenium2 WebDriver Ruby =>如何点击隐藏的链接

我在Ruby上使用Selenium 2 WebDriver。 如何点击隐藏的链接,用css(显示:无)? 链接是子菜单,鼠标hover在菜单上时可见。 //编辑: Selenium::WebDriver::Error::NoSuchElementError: Unable to locate element: {“method”:”link text”,”selector”:”submenu2″} 我将’:id’更改为’:link_text’,因为子菜单没有id。 导航: – menu1 – <– begin display:none – submenu1 + <–end submenu 当鼠标hover菜单时,您可以看到子菜单。 以前webdriver的子菜单不存在。 跟随代码我看到FF左下方menu1中的链接,但是子菜单没有打开并且因超时错误而中断。 menu = @driver.find_element(:link_text => “menu”) @driver.action.move_to(menu).perform wait.until { @driver.find_element(:link_text => “submenu”).click }

无法在60秒内获得稳定的firefox连接(127.0.0.1:7055)

我使用的是Firefox版本36.0.1和Selenium-Webdriver gem版本2.45.0。 我能够创建Firefox实例但无法继续使用脚本进行进一步操作无法在60秒(127.0.0.1:7055)错误中获得稳定的firefox连接。 有人能帮我吗 ?

Selenium Webdriver获取cookie值

我想获取一个cookie值,但不断收到的错误 我在打电话 @browser.cookie_named(“configsession”).each do |cookie| puts cookie[:name] 我有什么事我做错了吗?

如何使用selenium-webdriver(ruby)使用相同的浏览器窗口进行自动测试?

我正在使用selenium-webdriver和ruby中的黄瓜自动化网站的测试用例。 我需要每个function以特定顺序运行并使用相同的浏览器窗口。 每个function都会创建一个新窗口来运行测试。虽然在某些测试用例中需要这种行为 – 但在许多情况下并非如此。 从我的研究到目前为止,似乎有关于是否可以在整个测试用例中使用selenium驱动相同浏览器窗口的混合答案。 我遇到的大多数答案都是针对其他语言的,并且是针对浏览器特定的解决方案(我在测试IE时开发我的测试,但预计会在其他浏览器中运行这些测试)。 我在Ruby工作,从我读过的内容看起来似乎我必须为该页面创建一个类? 我很困惑为什么我必须这样做或如何帮助。 我的env.rb文件: require ‘selenium-webdriver’ require ‘rubygems’ require ‘nokogiri’ require ‘rspec/expectations’ Before do @driver ||= Selenium::WebDriver.for :ie @accept_next_alert = true @driver.manage.timeouts.implicit_wait = 30 @driver.manage.timeouts.script_timeout = 30 @verification_errors = [] end After do #@driver.quit #@verification_errors.should == [] end 到目前为止,我收集了一些有类似问题的人提供的信息: https : //code.google.com/p/selenium/issues/detail? id = 18 有没有办法将已运行的浏览器附加到java中的selenium webdriver ? 如果我的问题有任何不清楚的地方,请问我问题。 […]

如何使用Capybara获取HTML表格行

我正在尝试使用部分href xpath扫描HTML表中的行,并使用该行的其他列值执行进一步的测试。 link 29 33 485 45.2934,00 EUR link 22 93 485 38.336.934,123 EUR link 394 27 3844 3.485,2839 EUR 在cucumber-jvm步骤定义中,我很容易像下面那样执行它(我使用Ruby更舒服) @Given(“^if there are…$”) public void if_there_are…() throws Throwable { … … baseTable = driver.findElement(By.id(“blah”)); tblRows = baseTable.findElements(By.tagName(“tr”)); for(WebElement row : tblRows) { if (row.findElements(By.xpath(“.//a[contains(@href,’key=HONDA’)]”)).size() > 0) { List col = row.findElements(By.tagName(“td”)); tblData dummyThing = […]

selenium滚动元素进入(中心)视图

当一个元素与selenium不在视图中并且试图与它进行交互时,selenium通常会隐式地将元素滚动到视图中。 这很棒,但令人讨厌的是它通常会将元素放入视图中。 我的意思是,如果元素在窗口下方,它将向下滚动,直到元素刚好接近窗口边缘。 通常这很好,但是当在带有边框的网站上工作时,这将导致许多这类错误 Selenium::WebDriver::Error::UnknownError: unknown error: Element is not clickable at point (438, 747). Other element would receive the click: … 因为通常网页的边框位于其上方,但无论如何都会尝试单击该元素。 无论如何处理这个? 也许是在视线外时自动将元素移动到屏幕中心? 我正在考虑通过ruby修补猴子。

通过Ruby WebDriver获取chromes控制台日志

此问题之前已在Java中得到解答( Get chrome的控制台日志 ) 但是,我正在使用Ruby绑定,并想知道是否提供了类似的function? 我查看了Ruby源代码,但看不到任何提及或引用LoggingPreferences。 顺便说一句,我正在使用RemoteWebDriver并传入所需的function对象。 据推测,我想在该对象中设置日志记录首选项,但我很难看到哪里。