Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I have this page where there is a textbox and there is save button associated with each text box. I need to click on the save button so that it will save the value in text box. It is working manually and using selenium. But when running through Selenium WebDriver it's not saving the text box value. But there is no error exception being thrown. Input, Click is working. savetextvalue() is not triggered in short. There is similar issue Selenium click event does not trigger angularjs event

<pp-save-control fn-save-text="saveText();" btn-class="btn btn-default btn-mtl" button-id="btnkbaemailauthsub" place-holder-text="" input-class="tb-mtl" input-id="txtkbaemailauthsub" config-name="40" title-text="KBA email authentication subject" outer-container-class="div-mtl-header" class="ng-isolate-scope"><div class="div-mtl-header">
    <span class="label-mtl ng-binding">KBA email authentication subject</span><img ng-hide="(isHelpHidden != null &amp;&amp; isHelpHidden != 'true') ? false : true" class="help-mtl ng-hide" src="/Images/help.png">
    <div class="div-mtl-tb-holder">
        <input type="text" placeholder="" class="tb-mtl" name="txtkbaemailauthsub" id="txtkbaemailauthsub">
        <button ng-click="saveTextValue();" ng-hide="false" class="btn btn-default btn-mtl btn-mtl-alignment" name="btnkbaemailauthsub" id="btnkbaemailauthsub" type="button">save</button>
    </div>
</div>
</pp-save-control>

There are multiple text box and associated save button. Depending on the 'config-value'(You can see at top) value is getting saved.

share|improve this question
    
did you try with JavascriptExecutor. try with it or share the button unique id or xpath it will help – Shubham Jain Sep 10 '15 at 10:34
    
Tried with JavascriptExecutor also. – manutd Sep 10 '15 at 10:51

Replace the locator according to your convenience

WebElement element= driver.findElement(By.id("btnkbaemailauthsub"));

JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", element);

OR

JavascriptLibrary jsLib = new JavascriptLibrary();
jsLib.callEmbeddedSelenium(driver,"triggerMouseEventAt", element,"click", "0,0");

OR

WebElement element= driver.findElement(By.id("btnkbaemailauthsub"));
// Configure the Action
Actions action = new Actions(driver);

//Focus to element
action.moveToElement(element).perform();

// To click on the element
action.moveToElement(element).click().perform();

Hope it will help you :)

Get back to me if still facing issue :)

share|improve this answer
    
Thanks for the reply. Tried out this one. It was not working. – manutd Sep 10 '15 at 10:50
    
I have updated by answer. try with 2nd option JavascriptLibrary – Shubham Jain Sep 10 '15 at 11:19
    
It didn't work out :( Coordinates is respective to the web element right?. Not to the web page? – manutd Sep 10 '15 at 11:52
    
have to try to give focus? In my first code add this code before click event executor.executeScript("arguments[0].focus();", element); – Shubham Jain Sep 10 '15 at 11:59
    
It is focusing and clicking . But still it is not saved. There are more than 1 text boxes with save button attached to it. Can it cause any issue. Same saveTextValue being called? – manutd Sep 10 '15 at 12:20

Try putting in wait's in between your actions because Selenium doesn't know how angular loads and works. Protractor was created right for the purpose of handling angular web pages, which is a wrapper over selenium webdriver. However if you still want to test angularjs with Selenium then waiting for few seconds implicitly or fluent wait's between each action should help you with your need and accomplish what you intend to. Hope it helps.

share|improve this answer

In Selenium IDE try:

 <td>sendKeysAndWait</td>
 <td>id=mybutton</td>
 <td>${KEY_ENTER}</td>

same with Webdriver:

WebElement element_p = (new WebDriverWait(_driver, 3))
            .until(ExpectedConditions.visibilityOfElementLocated(By
                    .id("myButton")));
element_p.sendKeys(Keys.RETURN);
share|improve this answer
WebElement element= driver.findElement(By.id("btnkbaemailauthsub"));

JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", element);

Hi want under stand this code? How it actually working.

share|improve this answer
    
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. - From Review – CubeJockey Jan 12 at 13:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.