question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I am not able to click on element using any of the locators only javascript executor works for me in angular 2 pages

See original GitHub issue

Here is my html for angular 2 applications. I am executing my tests in chrome

<md-card-title _ngcontent-c10="" class="ra-card-title mat-card-title">
      <a _ngcontent-c10="">Massachusetts Division of Banks Issues Decision Establishing Limit on Maximum Allowable Fee for Dishonored Checks for State - Chartered Financial Institutions</a>
    </md-card-title>
<div _ngcontent-c10="" class="ra-card-header__footer">
      <md-card-subtitle _ngcontent-c10="" class="ra-card-code mat-card-subtitle">BLN3594</md-card-subtitle>
      
      <div _ngcontent-c10="" class="ra-card-menu">
        <span _ngcontent-c10="" aria-haspopup="true" class="ra-card-menu-button">...</span>
        <md-menu _ngcontent-c10="" role="menu" xposition="before" yposition="below"><!----> </md-menu>
      </div>
    </div>

<md-card-subtitle _ngcontent-c10="" class="ra-card-code mat-card-subtitle">BLN3594</md-card-subtitle>

I am not able to click on the menu button using

element(by.xpath("//span[@class='ra-card-menu-button'])[0]")).click();

But if I use below javascript executor , it is working fine.

var scrpt = "return document.getElementsByClassName('ra-card-menu-button')[0].click();";
        browser.executeScript(scrpt).then(function (text) {
            logger.log('info', 'Script is: ' + scrpt);

        });

protractor version is 5.1.1.

Could anyone please help me to identify the issue

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
wswebcreationcommented, May 17, 2017

Because by CSS means that you need to provide a . for classes and a # for ID’s. Now you are looking for the TAG ra-card-menu-button, you should use element(by.css('.ra-card-menu-button')).click();

Don’t then() here

0reactions
stemkar123commented, May 16, 2018

@Shobysukumaran Actually we have 400+ tests in out framework & it is extremly difficult to go & change each & every script to update the click(). 😦 Is there anything that I should update apart from Script.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to force Selenium WebDriver to click on element which is ...
Selenium determines an element is visible or not by the following criteria (use a DOM inspector to determine what css applies to your...
Read more >
How do I resolve the ElementNotInteractableException in ...
1. Wait until an element is visible / clickable WebDriverWait wait = new WebDriverWait(driver, timeout); wait.until(ExpectedConditions. · 2.
Read more >
JavascriptExecutor in Selenium Complete Guide
First of all, let's open Chrome developer tools then click the source tab. You will see the JavaScript codes. JavascriptExecutor in Selenium. In ......
Read more >
Testing Angular Applications with Selenium Java - Medium
Solution: Use JavascriptExecutor library. At times locating the web elements using locators like XPath, CSS, etc might not work as expected, especially when...
Read more >
How To Use JavaScriptExecutor in Selenium WebDriver?
At times, the click() method may not work on all the web browsers or the web controls might behave differently on different browsers....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found