Cypress test hangs at iframe - testing

When I run this test everything seems to work fine until I try click the button in the iframe. I have no problem selecting from the dropdown, but when I get to the last step where I want to click the button, the test hangs after the iframe has been loaded.
Also, is there a better way for me to load the iframe so that I dont have to get it every time ?
Here is my command:
require("cypress-xpath");
Cypress.Commands.add("old_report_export", function () {
cy.get('[id="isc_1A"]').type(Cypress.env("name"));
cy.get('[id="isc_1E"]').type(Cypress.env("password"));
cy.get('[id="isc_1Z"]').realClick();
cy.frameLoaded('[id="isc_3N"]');
cy.iframe('[id="isc_3N"]').contains("RETAINED").should("be.visible");
//Navigate to dashboard
cy.get('[name="isc_2Xicon"]').click();
cy.get("#isc_3Qtable > tbody > tr:nth-child(1) > td.menuTitleField > div").click();
cy.get("#isc_3Xtable > tbody > tr:nth-child(6) > td.menuTitleField").click();
cy.wait(10000);
cy.iframe('[id="isc_4H"]')
.find('[id="report_filter_dealer"]').select(this.testdata.dealer);
cy.iframe('[id="isc_4H"]')
.find('[id="report_filter_brand"]').select("Ford Thailand");
cy.iframe('[id="isc_4H"]')
.find('[id="report_filter_from_date"]').select("June 2023");
cy.iframe('[id="isc_4H"]')
.find('[id="load_page"]').select("All Pages - Report");
cy.iframe('[id="isc_4H]').find('[id="report-run-btn"]').realClick();
});
This is my test runner. It hangs there until cypress times out
I have tried using 'get' instead of find and ive tried 'click()' instead of 'realClick' as well as 'click({force: true})' all with no success

Okey, so I have now found that this works when I use the xpath to click the button. Why does it not work when I use the ID ?
cy.iframe('[id="isc_4H"]').xpath('//*[#id="report-run-btn"]').realClick();
This seems to work fine, but I know using the xpath could become problematic..

Related

How to access the menu item within a frame using Selenium Webdriver or Cypress?

I am having some trouble clicking a menu button on a webpage for work. The error occurs whether I am using Selenium or Cypress. While using cypress I get an uncaught exception error, and an error stating the (html) document cannot be read - while using selenium the element cannot be found.
After I login to the application I can't access anything.
driver.switchTo().defaultContent();
driver.switchTo().frame(driver.findElement(By.tagName("frameset")).findElements(By.tagName("frame")).get(1));
driver.findElement(By.cssSelector("body > table.section > tbody > tr > td > table > tbody > tr > td:nth-child(1)")).click();
I have tried to find it using the xpath as well. I'll also provide a snip of the html. Any help or guidance would be greatly appreciated.
To click on the <td> element you need to switchTo() the iframe ignoring the iframeset using either of the following locator strategies:
Using cssSelector:
driver.switchTo().defaultContent();
driver.switchTo().frame(driver.findElement(By.cssSelector("frame#1[src^='displayMenu']")));
driver.findElement(By.cssSelector("table.menubutton > tr > td")).click();
Using xpath:
driver.switchTo().defaultContent();
driver.switchTo().frame(driver.findElement(By.xpath("//frame[#id='1' and starts-with(#src, 'displayMenu')]")));
driver.findElement(By.xpath("table[#class='menubutton']//tr/td")).click();

PageSource() gets different code than appium inspector code

I am having a really hard time understanding the following problem, i have an app, i use appium inspector to see the elements, but when i use the elements, i get that the element is not found, therefore i printed the code using the driver.getPageSource() method, and i realized that the xml code that is created while running the app, is actually different to what appium inspector sees, what is the problem and how can it be solved? i could ask to the developers to fix it once i know the root cause, thanks in advance.
This is an example of a difference
Under < XCUIElementTypeOther name = Picture, Left Rear Corner> there are 4 more elements 2 StaticText, 2 Buttons (appium inspector) and on the the same element but in the java console, there are only 2 tags, so i do not see the 2 static text and the 2 buttons (which is what i want to click)
As you can see the code in the console is different to what i see in appium iinspector. this is for IOS app.
while (driver.findElementsById("Additional Videos").size() == 0) {
swipeScreenDown();
}
driver.getPageSource();
WebElement additionalVideos = driver.findElementByXPath("//XCUIElementTypeOther[#name=\"Picture, Left Front Corner\"]");
driver.getPageSource();
List<WebElement> idf = additionalVideos.findElements(By.className("XCUIElementTypeButton"));
driver.getPageSource();
System.out.println(idf.size());
driver.getPageSource();
idf.get(0).click();
driver.getPageSource();
Error got:
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
PageSource() action can print the visual elements at the screen.
As per my understanding, You are currently performing PageSource() action when loading the screen.
You need to click at the selected element
After click on this element use PageSource() action.
You get that element in the log of the PageSource().

element can't seem to be located in webdriverio script

Currently trying to test out the responsiveness on webdriverio. I adjust the viewport of my screen and then try to search for a table that exists at the bottom of the page (need to scroll to get into view port). For some reason, it can't locate the element and the test case fails.
it('should resize the table when screen width is mobile', () => {
let mobileTable = $('.overview-table.mobile-table');
browser.setViewportSize({
width: 767,
height: 500
});
//browser.pause(1500);
mobileTable.waitForExist(10000);
console.log(mobileTable);
mobileTable.scroll();
browser.debug();
});
I'm not sure if I'm getting the element right in the above code. I set mobileTable = $('.overview-table.mobile-table') because it is a table element with those classes
<table class="overview-table mobile-table"> ... </table>
I get the following error:
An element could not be located on the page using the given search parameters (".overview-table.mobile-table").
running firefox
Error: An element could not be located on the page using the given search parameters (".overview-table.mobile-table").
at scroll() - index.js:312:3
The problem most likely is in your selector.
You can verify if your selector is correct by testing it into your browser javascript console.
In chrome it goes like this:
Right click the page
Inspect
Select the "console" tab within the dev tool panel
Then simply type $$('.overview-table.mobile-table')
If that's an empty array, then you know the selector is wrong.

Click a Link working in Selenium Ide but not working in Webdriver

I am testing a scenario for the site "https://www.freecrm.com/index.html"
login credentials [ john2013 / john2013 ]
Scenario :
1 open the site https://www.freecrm.com/index.html
2 login with valid credentials
3 click on the "New Contacts" link
4 Add new contacts
using Selenium ide i am able to login and click on the "New Contact" link , but when i am trying to do the same thing using Webdriver [ java] i am not able to click the "New Contact" link
the code i have written is given below
driver.findElement(By.name("username")).clear()
driver.findElement(By.name("username")).sendKeys("john2013");
driver.findElement(By.name("password")).clear();
driver.findElement(By.name("password")).sendKeys("john2013");
driver.findElement(By.cssSelector("input[type=\"image\"]")).click();
The code up to the above is working fine but clicking the "New Contact" link
driver.findElement(By.xpath("//div[#class='noprint']/span[#class='headertext']/a[3]/")).click();
is not working though the same xpath is working in IDE.
i have tried with expected condition option , sleep but nothing is working.
can any one help me in this regard.
The problem is that your page uses a frameset. You should tell your webdriver which frame to use when it will search for your element. So try this:
driver.findElement(By.name("username")).clear()
driver.findElement(By.name("username")).sendKeys("john2013");
driver.findElement(By.name("password")).clear();
driver.findElement(By.name("password")).sendKeys("john2013");
driver.findElement(By.cssSelector("input[type=\"image\"]")).click();
//switch the driver to use one of the frames on your page. Potentially wait for a bit till the page is loaded
driver.switchTo().frame("mainpanel");
driver.findElement(By.xpath("//*[text()='New Contact']")).click();
Please change the xpath of link to
xpath=//a[contains(text(),'<whatevertext>')]
Incase if the same text link is already present in some part o the page we can proceed with occurences. Example if it is repeating second time:
xpath=(//a[contains(text(),'<whatevertext>')])[2]
If Nothing is working the best way is through java script executor.
First get the webelement of the link.
Then use the following code"
webelement=driver.findElement(by.xpath("=//a[contains(text(),'')]
"))
(JavaScriptExecutor)driver.executescript("argument[0].click();",webelement)
Actually Speaking //div[#class='noprint']/span[#class='headertext']/a[3]/ is absolute XPath.
as it ends with a[3] the position will vary always so it is advisable to use relative XPath/CSS
Suggested CSS:css=.noprint > .headertext > a.classname
Another Suggested CSS: css=.noprint > .headertext > a[attribute='value']
So we can use either of the above format.

Kendo UI grid select row via selenium web driver

I am trying to write a UI test for an application that uses a kendo grid. I am using selenium to drive the browser, and I am having trouble selecting a row in the grid.
I have been able to select the correct row like this:
IWebElement matterToSelect = MatterToSelectGrid.FindElement(By.XPath("//td[text()='" + matterId + "']/ancestor::tr"));
I was hoping to simply call .click() the webElement, but that did not work. So I tried building an action:
new Actions(Driver).MoveToElement(matterToSelect).Click().Build().Perform();
also no joy. Okay what about selecting it with js?:
IJavaScriptExecutor js = Driver as IJavaScriptExecutor;
js.ExecuteScript("return $(\"tr[data-uid='" + id + "']\").trigger('click');");
still nothing, what about a more direct selection just to see if it will work?
js.ExecuteScript("return $(\"#sourceGrid > table:nth-child(1) > tbody:nth-child(3) > tr:nth-child(1) > td:nth-child(1)\").click();");
grrrr still no luck. So my next thought was perhaps the kendo grid has a select() method I can use? Well it seems yes, but from what I read I also need to re-bind the grid? All the exaples I can find look something like this:
$("#sourceGrid").data("kendoGrid").select()
but I don't want to re-bind the grid from my test, so I have not tried this. Also, I am not sure what should be in data(), as all the grids are set up using the Html helper method, and use the .dataSource method to bind to action methods. Has anyone one got any better suggestions?
okay, I did it in the end like this:
IJavaScriptExecutor js = Driver as IJavaScriptExecutor;
js.ExecuteScript(String.Format("return $('td:contains(\"{0}\")').parent().addClass('k-state-selected');", matterId));
Don't get me wrong, I am not a fan of XPath but this is easiest way I found to select the first row in a Kendo grid. I gave my grid the Id of 'ticketGrid'. I then used Chrome Dev tools to inspect the first row. You can then right click and select 'Copy XPath' and I got this:
//*[#id='ticketGrid']/table/tbody/tr[1]
Then in my specFlow tests I have the following:
var wait = new WebDriverWait(WebDriver, timeout: TimeSpan.FromSeconds(5));
var firstRow = wait.Until(w => w.FindElement(By.XPath(#"//*#id='ticketGrid']/table/tbody/tr[1]")));
firstRow.Click();
Hope this helps