Selenium:我可以在 Selenium 中设置 WebElement 的任何属性值吗? [英] Selenium: Can I set any of the attribute value of a WebElement in Selenium?

查看:37
本文介绍了Selenium:我可以在 Selenium 中设置 WebElement 的任何属性值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 WebElement,我想将其属性值重置为其他值(例如 attr 是属性,我想更改其原始 value=1 到新的 value=10).

I have a WebElement, I want to reset its an attribute's value to some other value (for e.g. attr is the attribute, and I want to change its original value=1 to new value=10).

有可能吗?我正在使用 Selenium 2.0 (WebDriver.)

Is it possible? I am using Selenium 2.0 (WebDriver.)

推荐答案

您必须使用 JavascriptExecutor 类:

You would have to use the JavascriptExecutor class:

WebDriver driver; // Assigned elsewhere
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.getElementById('//id of element').setAttribute('attr', '10')");

这篇关于Selenium:我可以在 Selenium 中设置 WebElement 的任何属性值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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