本文介紹了如何設(shè)置“價(jià)值"?使用硒輸入網(wǎng)頁(yè)元素?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我的代碼中有如下所示的元素:
I have element in my code that looks like this:
<input id="invoice_supplier_id" name="invoice[supplier_id]" type="hidden" value="">
我想設(shè)置它的值,所以我用它的 xpath 創(chuàng)建了一個(gè) web 元素:
I want to set its value, so I created a web element with it's xpath:
val test = driver.findElements(By.xpath("""http://*[@id="invoice_supplier_id"]"""))
但現(xiàn)在我沒有看到設(shè)置值的選項(xiàng)...
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")
希望對(duì)你有幫助:)
這篇關(guān)于如何設(shè)置“價(jià)值"?使用硒輸入網(wǎng)頁(yè)元素?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!