1. <i id='E6dky'><tr id='E6dky'><dt id='E6dky'><q id='E6dky'><span id='E6dky'><b id='E6dky'><form id='E6dky'><ins id='E6dky'></ins><ul id='E6dky'></ul><sub id='E6dky'></sub></form><legend id='E6dky'></legend><bdo id='E6dky'><pre id='E6dky'><center id='E6dky'></center></pre></bdo></b><th id='E6dky'></th></span></q></dt></tr></i><div id='E6dky'><tfoot id='E6dky'></tfoot><dl id='E6dky'><fieldset id='E6dky'></fieldset></dl></div>
      <legend id='E6dky'><style id='E6dky'><dir id='E6dky'><q id='E6dky'></q></dir></style></legend>

    2. <small id='E6dky'></small><noframes id='E6dky'>

    3. <tfoot id='E6dky'></tfoot>

        • <bdo id='E6dky'></bdo><ul id='E6dky'></ul>

        如何设置“价值"?使用硒输入网页元素?

        How to set quot;valuequot; to input web element using selenium?(如何设置“价值?使用硒输入网页元素?)
          <bdo id='fBKuc'></bdo><ul id='fBKuc'></ul>

          <small id='fBKuc'></small><noframes id='fBKuc'>

            <tbody id='fBKuc'></tbody>

          1. <legend id='fBKuc'><style id='fBKuc'><dir id='fBKuc'><q id='fBKuc'></q></dir></style></legend>
          2. <tfoot id='fBKuc'></tfoot>

            <i id='fBKuc'><tr id='fBKuc'><dt id='fBKuc'><q id='fBKuc'><span id='fBKuc'><b id='fBKuc'><form id='fBKuc'><ins id='fBKuc'></ins><ul id='fBKuc'></ul><sub id='fBKuc'></sub></form><legend id='fBKuc'></legend><bdo id='fBKuc'><pre id='fBKuc'><center id='fBKuc'></center></pre></bdo></b><th id='fBKuc'></th></span></q></dt></tr></i><div id='fBKuc'><tfoot id='fBKuc'></tfoot><dl id='fBKuc'><fieldset id='fBKuc'></fieldset></dl></div>
                  本文介绍了如何设置“价值"?使用硒输入网页元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

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

                  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");
                  

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

                  或使用 JavascriptExecutor

                  WebElement element = driver.findElement(By.xpath("enter the xpath here")); // you can use any locator
                   JavascriptExecutor jse = (JavascriptExecutor)driver;
                   jse.executeScript("arguments[0].value='enter the value here';", element);
                  

                  (JavascriptExecutor) driver.executeScript("document.evaluate(xpathExpresion, document, null, 9, null).singleNodeValue.innerHTML="+ DesiredText);
                  

                  或(在 javascript 中)

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

                  希望对你有帮助:)

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

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                  • <small id='opZxC'></small><noframes id='opZxC'>

                      <bdo id='opZxC'></bdo><ul id='opZxC'></ul>
                      <tfoot id='opZxC'></tfoot>
                      <legend id='opZxC'><style id='opZxC'><dir id='opZxC'><q id='opZxC'></q></dir></style></legend>
                        <tbody id='opZxC'></tbody>

                          <i id='opZxC'><tr id='opZxC'><dt id='opZxC'><q id='opZxC'><span id='opZxC'><b id='opZxC'><form id='opZxC'><ins id='opZxC'></ins><ul id='opZxC'></ul><sub id='opZxC'></sub></form><legend id='opZxC'></legend><bdo id='opZxC'><pre id='opZxC'><center id='opZxC'></center></pre></bdo></b><th id='opZxC'></th></span></q></dt></tr></i><div id='opZxC'><tfoot id='opZxC'></tfoot><dl id='opZxC'><fieldset id='opZxC'></fieldset></dl></div>