How to set “value” to input web element using selenium?

后端 未结 3 769
自闭症患者
自闭症患者 2020-12-15 17:46

I have element in my code that looks like this:




        
相关标签:
3条回答
  • 2020-12-15 18:08
    driver.findElement(By.id("invoice_supplier_id")).setAttribute("value", "your value");
    
    0 讨论(0)
  • 2020-12-15 18:10

    Use findElement instead of findElements

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

    OR

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

    OR using 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);
    

    OR

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

    OR (in javascript)

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

    Hope it will help you :)

    0 讨论(0)
  • 2020-12-15 18:11

    As Shubham Jain stated, this is working to me: driver.findElement(By.id("invoice_supplier_id")).sendKeys("value"‌​, "new value");

    0 讨论(0)
提交回复
热议问题