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

2023-12-27

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

我可以获得一个属性值:

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

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


我认为修改链接的唯一方法是使用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"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

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

随机推荐