Watir-webdriver:如何在没有 js/jquery 的情况下更改属性值 [英] Watir-webdriver: how to change attribute value without js/jquery

查看:29
本文介绍了Watir-webdriver:如何在没有 js/jquery 的情况下更改属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I change a href attribute value using watir-webdriver without using js/jquery?

我可以得到一个属性值:

I can get an attribute value:

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

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

But I also need to change a bit of the href attribute value.

推荐答案

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

I think that the only way to modify the link is to use javascript. The code is quite maintainable since the element is retrieved using 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"

这篇关于Watir-webdriver:如何在没有 js/jquery 的情况下更改属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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