Issue
This is the method I'm using for sending keys and it's in my parent class:
public void sendKeysFunction(WebElement element, String value) {
waitUntilVisible(element);
scrollTElement(element);
element.clear();
element.sendKeys(value); }
And this is the way I'm calling it:
dc.sendKeysFunction(dc.BrandNameInput(),"bla bla");
My locators are in the dialog content class and I created a new object as dc so I'm calling my element from dialog content and the methods from parent class.
It's working on usual elements but there is a search-box for bringing the options when you type 3 letters. You can manually type all of the text also. But I cannot sending keys to this element with my test automation framework. It's clicking the element but not sending letters. I tried to use different solutions like Keys.ENTER but it didn't worked. I am sure of my locator. What should I do?
I am expecting to be able to send keys to my elements.
Solution
First of all check or change the element tag with which you try to interact. It is possible you have to interact with the ancestor or descender of the current element, or any other. It will be better if you provide, at least, schematically the structure of your element with the closest elements and tags. At least it isn't clear with which element you try to interact - not all HTML elements might be modified with sendKeys
method.
Generally, there are several ways to set text into a web element (input
), except sendKeys()
calling.
- JavascriptExecutor using:
JavascriptExecutor jsExecutor = (JavascriptExecutor) getDriver();
jsExecutor.executeScript("arguments[0].value = arguments[1];", element, "YOUR TEXT");
- For example, if
input
tag has thevalue
attribute you can try to set the value of this attribute:
WebElement element = ...
String script = "arguments[0].setAttribute(arguments[1], arguments[2]);";
jsExecutor.executeScript(script, element, "value", "YOUR TEXT");
- Using Action library:
Actions actions = new Actions(getDriver());
actions.sendKeys(element, "YOUR TEXT").perform();
Answered By - hhrzc
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.