无法使用硒找到文本框。错误如下:
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"proposedTagName"}
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>
答案 0 :(得分:0)
您可以使用driver.findElement(By.id("proposedTagName")).sendKeys("valuet");
类似的东西-
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");
}
}
答案 1 :(得分:0)
可能有时需要等待一段时间才能设置如下所示的值。
WebDriverWait wait = new WebDriverWait(driver, 60);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("proposedTagName")));
element.sendKeys("valuetobesend");
还要检查元素是否在框架内,如果是,则需要先切换到框架。
答案 2 :(得分:0)
请使用以下xpath和预期条件
XPath:
//table//input [@id='proposedTagName']
代码:
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);
答案 3 :(得分:0)
根据HTML,您共享的元素{"method":"id","selector":"proposedTagName"}
是一个<input>
标签,您可能需要向该元素发送字符序列。为此,您可能需要诱使 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");