Reputation: 27496
I am trying to set a text to input and then click on the hidden link (sounds maybe stupid but this is a workaround for another issue). So I've tried something like
WebElement element = webDriver.findElement(By.cssSelector("input[id$='inputId']"));
((JavascriptExecutor) webDriver).executeScript("arguments[0].style.visibility='visible';", element);
element.sendKeys(text);
I've also tried
((JavascriptExecutor) webDriver).executeScript("arguments[0].setText(" + text + ")", element);
or "arguments[0].text="someText"
None of these work, test always ends with
java.lang.IllegalArgumentException: Argument is of an illegal type: $Proxy30
When I debug it, I can see that element is correctly found but I am getting this exception during execution of the script. So what am I doing wrong here?
P.S. How do I click on that link, do I have to use JS Executor too?
Upvotes: 2
Views: 1405
Reputation: 38414
In semi-solid browsers, you can even search for the element via JavaScript, just run this:
var elem = document.querySelector("input[id$='inputId']");
elem.value = "some text";
Also note the use of value
. I haven't ever seen the setText()
method or text
attribute on an element, so maybe I am mistaken. But I'm sure that input values are set by the value
attribute.
In WebDriver:
JavascriptExecutor js = (JavascriptExecutor)webDriver;
js.executeScript(
"document.querySelector(\"input[id$='inputId']\").value = '" + someText + "';");
Upvotes: 2