[英]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.