NoSuchElementException when using Selenium/Java to automate Dynamics CRM

15 Views Asked by At

Using Selenium/Java to automate a basic workflow in Dynamics CRM web page.

So far I have successfully automated it to click the sign in button. Once I get to the Dynamics 365 Business Central homepage, I am trying to create a web element for the "Items" button.

ex. //Dynamics: Items button @FindBy(xpath="//*[@id=\"commandBarItemButton222\"]/span/span/span/span") private WebElement DynItemsButton;

Then I'm using the DynItemsButton.click() but every time it gives an NoSuchElementException though I believe the xpath is correct (I got the xpath from inspecting the element then in the source code I right clicked it and select copy xpath)

Now after doing some research, many people talked about iframes. I checked to see if this element was in an iframe which is why selenium couldn't find it. I found one iframe: Here is the iframe source code:

<iframe class="designer-client-frame" data-shimappoptions="{&quot;device&quot;:&quot;desktop&quot;,&quot;applicationId&quot;:&quot;FIN&quot;,&quot;isDesignerHost&quot;:true,&quot;aadTenantId&quot;:&quot;7b7466bb-fe1d-47a0-b943-8ded565c8e54&quot;}" src="https://businesscentral.dynamics.com/?noSignUpCheck=1&amp;aadTenantId=7b7466bb-fe1d-47a0-b943-8ded565c8e54&amp;startTraceId=d759a3ac2b6c4ff9b65e69685e3222e9&amp;tid=b0a46909-b683-4c5b-a95f-7483669d4de1&amp;runinframe=1" title="Main Content"></iframe>

now since I found an iframe I put in the following code to switch to the iframe before interacting with the element: WebElement iframe = driver.findElement(By.className("designer-client-frame")); driver.switchTo().frame(iframe);

now I run the code... and it says that the iframe element cannot be found.

I'm not sure what I'm doing wrong

edit: I am also using explicit wait times before each action so that it fully loads anything before interacting with it

0

There are 0 best solutions below