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
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It only takes a minute to sign up.
Sign up to join this communityI 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
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.
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.
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
Try:
Click Element xpath=//*[text()=' Sign Out ']
or either:
Click Element xpath=//*[text()=' Sign Out ']/parent::a