English 中文(简体)
利用Selenium Duncan在新表格中点击所有链接并打开所有点击链接
原标题:Clicking all links and open all clicked links in new tabs using Selenium Ruby

I want to open all clicked links in new browser tabs from the page I load using driver.get "http://www.example.com". I have got answer in other question I asked before but it is not working as I expected. Code is following:

require  rubygems 
require  selenium-webdriver 

driver = Selenium::WebDriver.for :firefox
driver.get " http://www.testfire.net "

driver.find_elements(:tag_name, "a").each {|link| link.click }

操作该密码的Selenium网络司机开车后,负荷要求上页,并在发现首个固定标签上点击,然后错失。

我也尝试了这一条:driver.find_element(:tag_name,“a”)send_keys [: Control, t ],这个条打开了新表格,但没有装页、空白表格。

我如何安排这种安排,以便我赢得错误,所有被点击的首页链接都将打开单独的浏览器表格?

我是否需要为此使用<代码>wait<>/code>?

[remote server] resource://fxdriver/modules/web_element_cache.js:9500:in `unknown : Element not found in the cache - perhaps the page has changed since it was looked up (Selenium::WebDriver::Error::StaleElementReferenceError)
        from [remote server] file:///C:/Users/AKASH/AppData/Local/Temp/webdriver-profile20120427-1496-sev0j4/extensions/[email protected]/components/command_processor.js:9069:in `unknown 
        from [remote server] file:///C:/Users/AKASH/AppData/Local/Temp/webdriver-profile20120427-1496-sev0j4/extensions/[email protected]/components/command_processor.js:9504:in `unknown 
        from [remote server] file:///C:/Users/AKASH/AppData/Local/Temp/webdriver-profile20120427-1496-sev0j4/extensions/[email protected]/components/command_processor.js:10510:in `unknown 
        from [remote server] file:///C:/Users/AKASH/AppData/Local/Temp/webdriver-profile20120427-1496-sev0j4/extensions/[email protected]/components/command_processor.js:10529:in `unknown 
        from [remote server] file:///C:/Users/AKASH/AppData/Local/Temp/webdriver-profile20120427-1496-sev0j4/extensions/[email protected]/components/command_processor.js:10534:in `unknown 
        from [remote server] file:///C:/Users/AKASH/AppData/Local/Temp/webdriver-profile20120427-1496-sev0j4/extensions/[email protected]/components/command_processor.js:10482:in `unknown 
        from D:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/response.rb:52:in `assert_ok 
        from D:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/response.rb:15:in `initialize 
        from D:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/http/common.rb:59:in `new 
        from D:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/http/common.rb:59:in `create_response 
        from D:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/http/default.rb:64:in `request 
        from D:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/http/common.rb:40:in `call 
        from D:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/bridge.rb:594:in `raw_execute 
        from D:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/bridge.rb:572:in `execute 
        from D:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/bridge.rb:354:in `clickElement 
        from D:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/common/element.rb:34:in `click 
        from selclick.rb:6:in `block in <main> 
        from selclick.rb:5:in `each 
        from selclick.rb:5:in `<main> 
问题回答

我确实认为,这是“按预期”的。

你们的先辈是正确工作的,然后是失败的。 错误确切说明了原因。 由于网页重载,物体参考资料不再指正确的链接。

我不敢肯定,如果是清楚的,那么就能够了解正在发生的情况。

你访问你的网页。 所有链接均按阵列收集。 关于你 lo首,你点击了你的第一个环节。 你访问这一链接只是同一个页。 你已不在你前面的网页上。 坡道的二度是上页链接。 这已不复存在,因为你将下页重新命名。 因此,错误。

你们究竟是怎样才能做到? 你们是否试图访问网站的每一页?

如果你再次试图把这个地点拖网,我可否建议机械化或安em?

Java

List<WebElement> elements = driver.find_elements( _locator_ );
for (i=0; i<elements.size(); i++) {
    List<WebElement> elements2 =driver.find_elements(_locator_) 

    WebElement ele = elements2.get(i);

    ele.click();
}




相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签