Selenium click event does not trigger angularjs ng-click

后端 未结 6 1357
眼角桃花
眼角桃花 2020-12-16 00:50

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 b

相关标签:
6条回答
  • 2020-12-16 01:14

    I faced this issue myself before. Here is how I solved it. Right click on the button -> Go to inspect element -> Copy css selector and store it in a variable

    The code to click the button :

    your_element = your_driver.find_element_by_css_selector(css_selector_variable)
    your_driver.execute_script('arguments[0].click()',your_element)
    
    0 讨论(0)
  • 2020-12-16 01:15
    driver = webdriver.Chrome('/path to /webdriver 22');
    driver.find_element_by_css_selector('button[ng-click="func()"]');
    
    0 讨论(0)
  • 2020-12-16 01:18

    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.

    0 讨论(0)
  • 2020-12-16 01:19

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

    0 讨论(0)
  • 2020-12-16 01:19

    The same issue happens when using Selenide over Selenium. I found a workaround using Selenide, if that is an option for you:

    After finding the clickable element, use Selenide's pressEnter() instead of click().

    element.should(exist).pressEnter();
    
    0 讨论(0)
  • 2020-12-16 01:23

    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);
    
    0 讨论(0)
提交回复
热议问题