Watir-webdriver:如何在没有js/jquery的情况下更改属性值

Ann*_*net 4 watir-webdriver

如何在不使用js/jquery的情况下使用watir-webdriver更改href属性值?

我可以得到一个属性值:

@browser.frames[2].div(:id,"mid-2").link(:class,"btn-lrg").attribute_value("href")
Run Code Online (Sandbox Code Playgroud)

但我还需要更改一些href属性值.

Jus*_* Ko 7

我认为修改链接的唯一方法是使用javascript.由于使用watir检索元素,因此代码非常易于维护.

#Get the first link (or any element you want)
element = browser.frame.link

#Check element's initial attribute
puts element.attribute_value('href')
#=> "page_a.html"

#Execute javascript to change the attribute
script = "return arguments[0].href = 'page_b.html'"
browser.execute_script(script, element)

#Check that the attribute has changed
puts element.attribute_value('href')
#=> "page_b.html"
Run Code Online (Sandbox Code Playgroud)