Selenium 2.0 Webdriver& Ruby,.text以外的链接元素方法? Navigate.to数组中的链接? [英] Selenium 2.0 Webdriver & Ruby, link element methods other than .text? Navigate.to links in array?

查看:175
本文介绍了Selenium 2.0 Webdriver& Ruby,.text以外的链接元素方法? Navigate.to数组中的链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将一些样本测试/规格从Watir转换为Selenium。在我的最后一个问题和建议的回复之后,我开始使用Selenium 2.0和WebDriver而不是Selenium 1.

I'm a bit further along in converting some sample test/specs from Watir to Selenium. After my last question here and suggested response, I began using Selenium 2.0 with WebDriver instead of Selenium 1.

有问题的例子涉及将表中的所有链接收集到数组 - 那部分是完整的。但是,一旦链接在数组中,我可以与它们交互的唯一有意义的方式似乎是.text。使用@ driver.navigate.to Array [1]在浏览器中给出了一个URL格式错误,而link.href或.src是无效选项。

The example in question deals with gathering all links within a table into an array -- that part is complete. However, once the links are in the array, the only meaningful way that I can interact with them appears to be .text. Using @driver.navigate.to Array[1] gives a URL format error in the browser, and link.href or .src are not valid options.

Watir实现收集这些链接(用户通过CMS添加的页面),将它们存储在一个数组中,然后逐个访问每个页面,提交一个潜在客户表单。我相信我可以使用Selenium工作并重新访问包含提示表单提交之间所有链接的主页,但这可能意味着数百个额外的页面加载,缓存与否。

The Watir implementation gathered these links (pages added by users via CMS), stored them in an array and then visited each page one by one, submitting a lead form. I believe I could get this to work using Selenium and revisiting the "home" page that contains all of the links between lead form submissions, but that could mean hundreds of extra page loads, cached or not.

到目前为止的代码:
'@ national = Array.new

The code so far: ' @countries = Array.new

@browser.navigate.to "http://www.testingdomain{$env}.com/global"  
@browser.find_elements(:xpath, "//table[@class='global-list']//a").each do |link|      
  @countries << [link.text, link.href]  ## The original WATIR line that needs an update
end #links  

@countries.uniq! #DEBUG for false CMS content'

我在selenium-webdriver文档中找到的最接近的项目是(字符串).attribute方法,但同样,我不确定什么属性

The closest item I could find in the selenium-webdriver documentation was the (string).attribute method, but again, am unsure of what attributes

推荐答案

我不确定使用的格式属性方法,但经过一些实验,我能够超越这一步。

I was not sure of the format for use with the attribute method, but after some experimenting I was able to move past this step.

@countries = Array.new

@ browser.navigate.tohttp://www.testingdomain {$ env} .com / global



@ browser.find_elements(:xpath,// table[@class='global-list']//a\").each do | link |

text = link.attribute(text)

href = link.attribute(href)

@countries<< [text,href]

end #links


` @ countries.uniq!错误CMS内容的#DEBUG

这篇关于Selenium 2.0 Webdriver&amp; Ruby,.text以外的链接元素方法? Navigate.to数组中的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆