Not able to click on the element

Viewed 235
<div class="MuiGrid-root jss48321 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 jss48324 MuiTypography-h4">Decks</h4>
<button class="MuiButtonBase-root MuiFab-root jss48323 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>

Since it is react js application, i added

browser.waitForAngularEnabled(false); 

Here i wanted to click on the add icon(+)

My test script. element(by.css('svg[class="MuiSvgIcon-root"]')).click();

Output: Failed: No element found using locator: By(css selector, svg[class="MuiSvgIcon-root"])

Can anyone please help me in resolving this issue.

2 Answers

try this

it('test case', async () => {
  let plusIcon = element(by.css('svg[class="MuiSvgIcon-root"]'))
  await browser.waitForAngularEnabled(false); 
  // your steps prior to click
  await browser.wait(
    ExpectedConditions.presenseOf(plusIcon),
    15000
  );
  await plusIcon.click();
});

Assuming your application is not using iFrame.

please try the following code:

onPrepare: function() {
browser.manage().window().setSize(1920, 1080);
}


describe('Click plusIcon', () => {
it('Click PlusIcon', async () => {
let plusIcon = element(by.css('svg[class="MuiSvgIcon-root"]'))
const EC = protractor.ExpectedConditions;
var a = await browser.wait(EC.visibilityOf(plusIcon), 90000);
console.log("the value of a is:", a);
await plusIcon.click();
 });
});

let's find the actual issue here.

First, let's print the value of a.

if a is true, then plusIcon is visible. And, if you get the error for not clicking the button then you either need to maximize the browser or scroll to the button.

if a is false, then plusIcon is not visible yet. Either we need to wait for some more extra time.

Related