0
<div class="MuiGrid-root jss45 MuiGrid-item MuiGrid-grid-xs-12 MuiGrid-grid-sm-3 MuiGrid-grid-md-3 MuiGrid-grid-lg-3 MuiGrid-grid-xl-3">
<h4 class="MuiTypography-root jss48 MuiTypography-h4">Decks</h4>
<button class="MuiButtonBase-root MuiFab-root jss47 MuiFab-sizeSmall MuiFab-primary" tabindex="0" type="button" aria-label="add" title="Add">
<span class="MuiFab-label"><svg class="MuiSvgIcon-root" focusable="false" viewBox="0 0 24 24" aria-hidden="true">
<path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z">
</path>
</svg>
</span>
<span class="MuiTouchRipple-root">
</span>
</button>
</div

Java Scriprt:

describe('Login', function () {
it('Login', function () {
browser.waitForAngularEnabled(false);// since it is React JS application
browser.get('http............');// cannot access this. since it requires vpn
element(by.css('input[type="text"]')).sendKeys('Username');
element(by.css('input[type="password"]')).sendKeys('Password');
element(by.buttonText('Login')).click();
element(by.css('svg[class="MuiSvgIcon-root"]')).click();
});
});

In the above code, I wanted to click on the add button. I tried with all locators. But I am getting element not found error. Can anyone please help me in resolving this

Explorer
  • 79
  • 7

2 Answers2

0

SVG are not reliable locator elements. Instead use title attribute of the button.

element(by.css('button[title="Add"]')).click();
AbhishekGowda28
  • 727
  • 6
  • 15
  • Failed: No element found using locator: By(css selector, button[title="Add"]) is displaying. – Explorer Feb 16 '21 at 04:19
  • Can you verify the element is present, by running the following command in the browser dev-tools document.querySelector(button[title="Add"]') – AbhishekGowda28 Feb 16 '21 at 16:46
  • Uncaught ReferenceError: button is not defined at :1:24 The above message is displayed after running the command – Explorer Feb 17 '21 at 10:18
0

Try with the below css locator.

add some waits before you inspect the element using browser.sleep(3000);

const ele = element(by.css('button[title="Add"]'));

ele.click();

Hope the above code resolves the issue.

Madhan Raj
  • 1,368
  • 1
  • 5
  • 12