There are circumstances when we need to manipulate the web page in order to test some scenarios:
Below are some examples in C#:
Use JavaScript to Change Value
Changing value of an input field with ID input-confirm to iambot to simulate SpamBot’s action:
IJavaScriptExecutor js = driver as IJavaScriptExecutor;js.ExecuteScript(“$(‘#input-confirm’).val(‘iamabot’)”);
Use JavaScript to Disable Client Side Validation
Remove JavaScript validation classes from submit button and form before clicking on button. This test case is to ensure that we do have server side validation in place.
var js = driver as IJavaScriptExecutor;
js.ExecuteScript(“$(‘button.primary-cta.button.fn_validate_submit’).removeClass(‘button.primary-cta.button.fn_validate_submit disabled’)”);
js.ExecuteScript(“$(‘form’).removeClass(‘form fn_validate fn_validate_container’)”);
Leave a Reply