I have a page which appears with some pre-filled data in input boxes. I want to select the input box which has my desired content, based on the content itself. This content isn't part of page HTML, but rather appears as value attribute in the element properties.
I have written a simple HTML file (test.html) to demonstrate the problem:
<!DOCTYPE html>
<html>
<head>
<title> Hello </title>
</head>
<body>
<div id="test">
<input type="text"> <br> <br>
<input type="text"> <br> <br>
<input type="text"> <br> <br>
</div>
<script type="text/javascript">
let input_nodes = document.querySelectorAll("input")
for(var i = 0; i < input_nodes.length; i ) {
input_nodes[i].value = 'value_' i;
}
</script>
</body>
</html>
On this page I want to select the element with entered value as value_1. It doesn't appear in page HTML, but can be seen in element properties.

CodePudding user response:
Using test.html file in my local, I could see 3 input box in UI
As you can see this xpath
//div[@id='test']//input[2]
represent the node that you've been looking to do send_keys
CodePudding user response:
Try this:
String preFilledValue = "value_1";
List<WebElement> elements = driver.findElements(By.xpath("//div[@id='test']/input"));
for (WebElement ele : elements) {
if (preFilledValue.equals(ele.getAttribute("value"))) {
System.out.println("Element found");
}
}
}

