How on earth I get this Javascript method
$('#principal_uid').change(function() {
if($(this).val().length > 0){
window.location.href = "/switch.html" + "?uid=" + $(this).val();
} else {
window.location.href = "/index.html";
To work with my Selenium WebDdriver test, where I try to change the field’s value?
The problem is the field has a default value, but Selenium clear()-method does not clear it, although the test is passing.
I’ve tried something
WebElement field =driver.findElement(By.id("principal_uid"));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("$('#principal_uid').change");
field.clear();
field.sendKeys("newValue"+Keys.RETURN); //CHRASHED THE TEST WITH ERROR COMMUNICATING REMOTE SERVER ERROR
Try something like this:
this should trigger the “onchange” event and redirect you to the page as described in the code.
if the event is not triggered (although it should be) you can add: