Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium click event does not trigger angularjs ng-click

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.

like image 913
manutd Avatar asked Sep 10 '15 10:09

manutd


People also ask

How do you trigger a click event in AngularJS?

The syntax is the following: function clickOnUpload() { $timeout(function() { angular. element('#myselector'). triggerHandler('click'); }); }; // Using Angular Extend angular.

How does selenium handle ng click?

find_element_by_class_name() doesn't accepts multiple class name. Instead you can use css selector . To avoid synchronization issue Induce WebDriverWait() and wait for element_to_be_clickable() and following css selector. You need to import below libraries.

Why click is not working in selenium?

We can list the most common reasons for click problems as being one of the following: Wrong web element locations. The existence of a web element that obscures the web element that we want to click. The Selenium WebDriver works much faster than the response of the application.

Does selenium work with AngularJS?

Selenium API has implementations in several major programming languages - allowing you to write your tests in Java, C#, python, ruby, JavaScript and more. If you already have a selenium-based e2e testing framework in place - you can use it also for AngularJS web-apps.


2 Answers

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 :)

like image 160
Shubham Jain Avatar answered Oct 19 '22 13:10

Shubham Jain


driver = webdriver.Chrome('/path to /webdriver 22');
driver.find_element_by_css_selector('button[ng-click="func()"]');
like image 24
ayoub laaziz Avatar answered Oct 19 '22 13:10

ayoub laaziz