I’m working on an application that does not contain id attribute for few textboxes .Other txtboxes have id.If I don’t use the focus event I’m not able to use ‘sendKeys’ for setting the values for textboxes.
Hence I used
js.executeScript ("document.getElementById('x').focus()");
But since some textboxes don’t have an id attribute i can’t use the above hence tried using
js.executeScript ("document.getElementByName('xyz').focus()");
Ondoing this following exception msg is generated:
org.openqa.selenium.WebDriverException: document.getElementByName is not a function (WARNING: The server did not provide any stacktrace information); duration or timeout: 26 milliseconds
I do not believe there is a
getElementByName. You need to dogetElementsByName(note the ‘s’ for Elements).getElementsByNamereturns a collection, so you will need to specify the index: