Home > database >  Knock out js selenium web driver accept text input
Knock out js selenium web driver accept text input

Time:10-17

I have a text box and button where I used knock out js binding as follows

<textarea id="txtSite" cols="40" rows="5" data-bind="value: cellSite" data-required-msg="required" required="required" ></textarea>
 <button id="btnSubmit" value="Submit" data-bind="click: SubmitCell">Submit</button>

I am trying to automate using selenium by entering some required text in to textbox and submit but it is always firing an validation even though the value is present. How to make the button understand the value is entered in to textbox

  driver = new EdgeDriver(@"C:\Tools\EdgeDriver");
  driver.Url = "myurl";
  driver.Manage().Window.Maximize();
  Thread.Sleep(3000);
  Helper.SendKeys(driver, By.Id("txtSite"), "xyz");
  WebElement submitBtn = (WebElement)driver.FindElement(By.Id("btnSubmit"));
  Helper.JavaScriptClick(driver, submitBtn);

I keep on getting alert asking to enter value in textbox field is there a way to handle this

CodePudding user response:

OK here is what I found and it works as expected

Helper.SendKeys(driver, By.Id("txtSite"), "test");
Thread.Sleep(2000);
IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;
IWebElement webElement = driver.FindElement(By.Id("txtSite"));
jse.ExecuteScript("$(arguments[0]).change();", webElement);

CodePudding user response:

Can't test with Selenium but I'd recommend trying the textInput binding, Unlike the value binding, textInput provides instant updates from the DOM.

Looks like you're bumping that change event manually, which is equivalent to clicking out of the input (triggering change event) as you would as a user - to click the submit button.

https://knockoutjs.com/documentation/textinput-binding.html

  • Related