Nightwatch js can't click a tab - nightwatch.js

I m writing a night watch js e-t-e test for my site. My site has a right hand tabs that are use as a menu that allow user to navigate. Te problem is my niightwatch is not able to perform click on the tab. I tried everything possible to no avail.
.verify.elementPresent('div[role="tab"][title="Asset Index"]')
.click('#right-tab-list div:nth-child(5)', function(status){
console.log('the click status is', status.status);
browser.click('#right-tab-list div:nth-child(5)');
})
.waitForElementVisible('div[role="tab"][aria-selected="true"][title="Asset Index"]', 3000)
.verifying div[role="tab"][title="Asset Index"] present returns positive. However, the click on the div:nth-child(5) of the #right-tab-list failed. The 5th child is the div[role="tab"][title="Asset Index"] . The click status returns -1.Before i my code was
.verify.elementPresent('div[role="tab"][title="Asset Index"]')
.click('div[role="tab"][title="Asset Index"]', function(status){
console.log('the click status is', status.status);
browser.click('#right-tab-list div:nth-child(5)');
})
.waitForElementVisible('div[role="tab"][aria-selected="true"][title="Asset Index"]', 3000)
verifying the element present returns true . However the click status returns negative . The proceeding waitForElementVisible failed as well. I tried everything possible to no aveil. It was working 4 months back though. I just am not sure why not today. Any help would be appreciated.

Have you tried verifying that #right-tab-list div:nth-child(5) is present before you try to click it?

Related

Laravel dusk coming back to original browser tab or close latest tab but keep original

I have situation where I need to click the link and visit new tab and see if there is that particular text or not and then come back to original tab and perform some work.
this is the code I am using to confirm I am in latest browser tab after clicking view button
$window = collect($this->driver->getWindowHandles())->last();
$this->driver->switchTo()->window($window);
Now I have to come to original tab, How can i do that ? Any help?
is there any way to close recent tab after some time. so that i can come to original tab.
Thanks
You're on the right track.
You can continue with something like this:
$this->browse(function (Browser $browser) {
$browser->visit('/')->click('#some-link');
// switch to the last tab
$window = collect($browser->driver->getWindowHandles())->last();
$browser->driver->switchTo()->window($window);
// make some assertion on that tab
$browser->assertRouteIs('some-route.alias');
// switch back to first tab
$window = collect($browser->driver->getWindowHandles())->first();
$browser->driver->switchTo()->window($window);
// TODO: make further assertions
});

How to verify element displays in new window after clicking a link on the main window

I am using Cypress to click a link on the Homepage which opens the respective page in the new window. I am not able to identify any element on this page. I am doing this to verify that the click opens the correct page.
I saw the link: Access a new window - cypress.io which didn't help much to answer the problem.
Please suggest if there is some way to test this.
I have tried few things like:
cy.window().contains('.div.trItem')
cy.window().its('.trValue).should('eq','SomeHeading')
cy.url().should('include', '/theLink1.html/')
Expected:
- Clicking link open the correct page in new window
- Identify URL in new window includes some text
- Certain text displays on the new window
First of all, you can't access to another tab or window with Cypress. Consider to separate your test cases. For example, in one test you could check that a element contains href attribute with expected url and target attribute with _blank.
Like this:
it('contains valid a element', () => {
cy.visit('https://example.cypress.io/')
cy.contains('Cypress.io').should('have.attr', 'href', 'https://www.cypress.io').should('have.attr', 'target', '_blank')
})
And in second test check that your other page contains expected text.

RobotFramework: Goes

Below is code where i go to a new window. I do a screenshot to ensure that i am on the right window
${url}= Get Element Attribute xpath=//*[contains(text(),'Download certificate')]#href
Select Window Containing Url ${url}
Page Screenshot certificates
Wait Until Element Is visible xpath=//*[contains(text(),"SUCCESSFULLY COMPLETED THE MODULE")]
Not found according to error message.
Element locator 'xpath=//*[contains(text(),"SUCCESSFULLY COMPLETED THE MODULE")]' did not match any elements after 30 seconds
However i know from firebug that this xpath will match on the page. My uneducated theory is that the focus is still on the former page - would this be correct and regardless, what can i do to ensure that commands go to the correct new page?
You could use Select Window new.
See documentation here

How to get more detail about error when element not presented, Nightwatch.js?

I using Nightwatch.js + Selenium for acceptance testing and it generates html report after finish.
And sometimes when some element not presented on the page - Nightwatch will return an error, so, this code:
.waitForElementPresent('.block', 15000)
will return this error:
Timed out while waiting for element to be present for 15000 milliseconds. - Expected "found" but got: "not found"
I want to see more details about element which not presented
I really do not get the point,what do you want to know more?
The elements is not found so that it return you not found.
Before you go to code, open the browser, press F12 and find ".block" in element tab, make sure the element is present/visible then code ,or you just right-click on the element you want then chose copy selector.
If you want more detail about the element,go to console tab,paste this one and you will see the detail of '.block' element.
document.querySelectorAll('.block')

CasperJS click event having AJAX call

I am trying to fetch data from a site by simulating events using CasperJS with phantomJS 1.7.0.
I am able to simulate normal click events and select events. But my code fails in following scenario:
When I click on button / anchor etc on remote page, the click on remote page initiates an AJAX call / JS call(depending on how that page is implemented by programmer.).
In case of JS call, my code works and I get changed data. But for clicks where is AJAX call is initiated, I do not get updated data.
For debugging, I tried to get the page source of the element container(before and after), but I see no change in code.
I tried to set wait time from 10 sec to 1 ms range, but that to does not reflect any changes in behavior.
Below is my piece of code for clicking. I am using an array of CSS Paths, which represents which element(s) to click.
/*Click on array of clickable elements using CSS Paths.*/
fn_click = function(){
casper.each(G_TAGS,function(casper, cssPath, count1)
{
casper.then ( function() {
casper.click(cssPath);
this.echo('DEBUG AFTER CLICKING -START HTML ');
//this.echo(this.getHTML("CONTAINER WHERE DETAILS CHANGE"));
this.echo('DEBUG AFTER CLICKING -START HTML');
casper.wait(5000, function()
{
casper.then(fn_getData);
}
);
});
});
};
UPDATE:
I tried to use remote-debug option from phantomJS, to debug above script.
It is not working. I am on windows. I will try to run remote debugging on Ubuntu as well.
Please help me. I would appreciate any help on this.
UPDATE:
Please have a look at following code as a sample.
https://gist.github.com/4441570
Content before click and after click are same.
I am clicking on sorting options provided under tag (votes / activity etc.).
I had the same problem today. I found this post, which put me in the direction of jQuery.
After some testing I found out that there was already a jQuery loaded on that webpage. (A pretty old version though)
Loading another jQuery on top of that broke any js calls made, so also the link that does an Ajax call.
To solve this I found http://api.jquery.com/jQuery.noConflict/
and I added the following to my code:
this.evaluate(function () { jq = $.noConflict(true) } );
Anything that was formerly assigned to $ will be restored that way. And the jQuery that you injected is now available under 'jq'.
Hope this helps you guys.

Resources