如何设置“价值”用硒输入网页元素? [英] How to set "value" to input web element using selenium?

查看:151
本文介绍了如何设置“价值”用硒输入网页元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码中的元素如下所示:

I have element in my code that looks like this:

<input id="invoice_supplier_id" name="invoice[supplier_id]" type="hidden" value="">

我想设置它的值,所以我用它的xpath创建了一个web元素:

I want to set its value, so I created a web element with it's xpath:

 val test = driver.findElements(By.xpath("""//*[@id="invoice_supplier_id"]"""))

但现在我没有看到设置值的选项......

but now I dont see an option to set the value...

推荐答案

使用 findElement 而不是 findElements

driver.findElement(By.xpath("//input[@id='invoice_supplier_id'])).sendKeys("your value");

OR

driver.findElement(By.xpath("//input[@id='invoice_supplier_id'])).setAttribute("value", "your value")

OR

driver.findElement(By.id("invoice_supplier_id")).setAttribute("value", "your value");

希望它能帮到你:))

这篇关于如何设置“价值”用硒输入网页元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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