0

enter image description here

I am trying to click on sign out link, but not able to succeed: I tried the below ways,

Click Element    class=mat-icon.notranslate.mat-primary.material-icons
Click Button     name=Sign Out
Click Element    name=Sign Out
1
  • what error are you getting? import org.openqa.selenium.NoSuchElementException or ElementClickInterceptedException etc. On the basis of that, there will be a concrete solution. Nov 14, 2019 at 13:43

4 Answers 4

2

Selenium probably is not working properly against this Angular custom element. You can try to execute Javascript to perform the clicking.

JavascriptExecutor js = (JavascriptExecutor)driver;
WebElement button = driver.findElement(By.cssSelector(".mat-icon"));
js.executeScript("argument[0].click();", button);

However, this is a symptom of a problem: Angular applications have a custom DOM structure that is not supported properly by WebDriver. Protractor provides the support for Angular E2E automated checking.

1

It looks like you are targeting an element with the name of "Sign Out". However, from the code snippet, there is no element with the name "Sign Out". The name attribute is not on the tag.

If this is the only element with this class, you can try:

Click Element  class=mat-menu-item

Or, since it's a link:

Click Element  link=Sign Out

You can also try to use a CSS Selector or an Xpath to target this element.

1
  • I tried to click the element using class=mat-menu-item before but it gives me an error message saying, ElementClickInterceptedException: Message: element click intercepted: Element <a _ngcontent-c26="" class="mat-menu-item ng-star-inserted" mat-menu-item="" role="menuitem" tabindex="0" aria-disabled="false">...</a> is not clickable at point (1303, 86). Other element would receive the click: <div id="cdk-overlay-0" class="cdk-overlay-pane" style="pointer-events: auto; position: static;">...</div>
    – Adarsh99
    Nov 17, 2019 at 10:27
1

Hi sometimes click action does not work on all elements, try clicking the parent element:

Also your page is angular , and hence might works asynchronously. So try waiting for element

wait until page contains element    css:*[class="mat-menu-item"]


Click Element    css:*[class="mat-menu-item"]

Or any parent element up in the hierarchy

Usually click works in elements like input, button, and elements with clickable property for angular pages

5
  • I tried this option before it gives an element not found error which is as below Element with locator 'class=mat-icon.notranslate.mat-menu-item' not found. I tried to add implicit wait as well.
    – Adarsh99
    Nov 17, 2019 at 10:32
  • @Adarsh99 I edited my answer, Could you try this.
    – PDHide
    Nov 17, 2019 at 10:40
  • in chrome, do ctrl+f12 on your web page and goto element, then press ctrl+f , and then paste *[class="mat-menu-item"], make sure there is only one element. Then use the above command in my answer
    – PDHide
    Nov 17, 2019 at 10:45
  • Yes there in only one element I find when I search, But this also does not work, Element with locator 'css=*[class="mat-menu-item"]' not found. error displayed.
    – Adarsh99
    Nov 17, 2019 at 10:53
  • @Adarsh99 try explicit wait as in my updated comment , your page is loaded asynchronously
    – PDHide
    Nov 17, 2019 at 11:53
0

Try:

Click Element    xpath=//*[text()=' Sign Out ']

or either:

Click Element    xpath=//*[text()=' Sign Out ']/parent::a

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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