简体   繁体   English

无法使用硒在文本框中插入文本

[英]Unable to insert text within text box using selenium

Unable to locate text box using selenium. 无法使用硒定位文本框。 Error is as follows: 错误如下:

 org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"proposedTagName"}

HTML: HTML:

<div id="content">
<div id="addTagDiv" class="overlay" style="height: 50px">
    <form id="addTagForm" action="inserttag" method="post">
        <div class="floatLeft" style="margin-right: 15px">
            <table class="formTable">
                <tbody><tr>
                    <td class="inputTitleCell">New Tag Name:</td>
                </tr>
                <tr>
                    <td><input id="proposedTagName" name="tagName" type="text" class="textInput baselineVersionInput" value="" maxlength="100"></td>
                </tr>
            </tbody></table>
        </div>
        <div class="floatRight">
            <table class="formTable">
                <tbody>
                <tr>
                    <td><input id="addTagSubmitButton" class="addNewTagSubmitButton" type="submit" value="Create New Tag"></td>
                </tr>
            </tbody></table>
        </div>
    </form>
</div>

You can do it using driver.findElement(By.id("proposedTagName")).sendKeys("valuet"); 您可以使用driver.findElement(By.id("proposedTagName")).sendKeys("valuet");

Something like this - 像这样-

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class A {

    public static void main(String[] args) {

        System.setProperty("webdriver.chrome.driver", chromeDriverPath); //the path of chrome exe here
        WebDriver driver = new ChromeDriver();
        WebDriverWait wait = new WebDriverWait(driver, 10);
        driver.get("url here");
        WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("proposedTagName")));
        element.sendKeys("value");
    }

}

May be you need to wait sometimes before setting the value as given below. 有时可能需要等待一段时间才能设置如下所示的值。

WebDriverWait wait = new WebDriverWait(driver, 60);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("proposedTagName")));
element.sendKeys("valuetobesend");

Also, check the element is inside frame, if it is then, need to switch to the frame before. 另外,检查元素是否在框架内部,如果是,则需要先切换到框架。

Please use the below xpath along with expected conditions 请使用以下xpath和预期条件

XPath: XPath:

//table//input [@id='proposedTagName']

Code: 码:

String value="XXXXX";
WebDriverWait wait=new WebDriverWait(driver,30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//table//input[@id='proposedTagName']")));
driver.findElement(By.xpath("//table//input[@id='proposedTagName']")).sendKeys(value);

As per the HTML you have shared the element {"method":"id","selector":"proposedTagName"} is a <input> tag and you possibly need to send character sequence to the element. 按照HTML,您已共享元素{"method":"id","selector":"proposedTagName"}<input>标记,您可能需要将字符序列发送到该元素。 To achieve that you may need to induce WebDriverWait for the desired element to be clickable and you can use the following solution: 为此,您可能需要诱使WebDriverWait使所需元素可单击,并且可以使用以下解决方案:

new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//form[@id='addTagForm']//following::table[1]//input[@class='textInput baselineVersionInput' and @id='proposedTagName']"))).sendKeys("A.Prakash");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法使用 Selenium Java 提取手风琴内的段落文本 - Unable to extract the paragraph text within an accordion using Selenium Java 无法使用 Selenium Webdriver 在 Twitter 上的 Compose new Tweet box 中输入文本 - Unable to enter text in Compose new Tweet box on Twitter using Selenium Webdriver 如何在Selenium Webdriver的多个文本框中插入值 - how to insert value in multiple text box in selenium webdriver 如何根据垂直参数在硒webdriver的文本框中插入值 - how to insert value in text box in selenium webdriver according to perticular parameter 使用Robot类和Selenium WebDriver将大写文本发送到文本框 - Send caps text to a text box using Robot class & Selenium WebDriver 无法使用Java在Selenium WebDriver中找到/填充文本框 - Unable to locate/populate Text box in Selenium WebDriver with Java 无法在Selenium Java中选择输入文本框元素 - Unable to select input text box element in selenium java 如何识别<a>使用 Selenium 和 Java</a>中的文本 - How to identify the text within the <a> using Selenium and Java 在Selenium中同时使用文本和位置getattribute() - Using both text and position within Selenium getattribute() 无法使用 Selenium Java 获取强标记中存在的文本值 - Unable to get text values present within strong tag using Selenium Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM