I have a selenium test in java that works fine on DEV environment using a function findElement(By.xpath("actual xpath")).getAttribute("actual attribute")
, which is getting me a value of an input. I tried the same test run on PROD environment, but it couldn't find this attribute. For some reason the value of this input is not visible anywhere in the xpath. I know the input's id, so I wrote in my browser's console a simple javascript function document.getElementById("actual id").value
and it returned the correct value that I need, so that information is sadly hidden from java, but not from javascript. Is there a way, how can I use this javascript function in my java code?
Here's what I tried:
String id = driver.findElement(By.xpath("//label[text()='First Name(s)']")).getAttribute("for");
JavascriptExecutor js = (JavascriptExecutor) driver;
String method = "\"return document.getElementById('" + id + "').value;\"";
Object name = js.executeScript(method);
As you can guess, it didn't work. Object name
is returning just null
.
I'm sure that the id
is correct, verified it by debug, so I had to do a mistake somewhere else.
DEV environment:
<input _ngcontent-eqp-c44 class="input-element ng-untouched ng-pristine ng-valid" ng-reflect-model="John" id="input_id_3301863451932101" type="text">
I need the value "John" from ng-reflect-model
which is super easy on this environment, but
PROD environment:
<input _ngcontent-xjq-c2 class="input-element ng-untouched ng-pristine ng-valid" id="input_id_6695429395219272" type="text">
There you can see more of the HTML
there is just nothing I can use with java...