error while I try to click by button in Nigthmare.js - nightmare

I try to create a code that should help me automates the process of biding. I use Nightmare.js and when I am trying click button it returns error. Which says: Error: Unable to find element by selector: .MenuItemButton__1ijozEjL3V.here is my code
This method finds element by selector with document.querySelector. And button with this selector is on the pagecontent of the page but this element is not found by Nightmare.js. What might be wrong with my code? I have never tried webs-crapping before. Any advices will be appreciated

Related

codeceptjs react testing - Clickable element was not found by text|CSS|XPath

I have a project made with react and rest api(php+mysql).I have to put it through a codeceptjs test.The app is working properly with countless of manual testing, and as far as I can see, the codeceptjs test is working too, but it gives the following error:
Error: Clickable element "ADD" was not found by text|CSS|XPath
at new ElementNotFound (node_modules/codeceptjs/lib/helper/errors/ElementNotFound.js:14:11)
at assertElementExists (node_modules/codeceptjs/lib/helper/WebDriver.js:2835:11)
at WebDriver.click (node_modules/codeceptjs/lib/helper/WebDriver.js:917:7)
at processTicksAndRejections (internal/process/task_queues.js:97:5)I }) => {
I.amOnPage('/');
I.click('ADD');
I.seeElement('#product_form');
I.fillField('#sku', 'SKUTest000');
I.fillField('#name', 'NameTest000');
I.fillField('#price', '25');
I.waitForElement('#productType');
I.selectOption('#productType','DVD');
I.waitForElement('#size');
I.fillField('#size','200');
I.click('Save');
My add element looks like this:
<Link title="ADD" to="/add-product">ADD</Link>
Can someone please help me out why is this error appearing and how can I solve it? Thanks in advance!
Update:
I did a couple more tests, and I noticed that sometimes it gives back less/different errors depending on the test's time. For example:
http://165.227.98.170/open?testName=ed
http://165.227.98.170/open?testName=ah
http://165.227.98.170/open?testName=bc
My guess is that is has to do with how react loads in the html elements and manages the rest api calls. How/what should I change in the app to accomodate the test script?
Seems like the problem was I put the whole home page's load after the rest api call by accident.

React JS - Unable to find an element by data-testid

I am writing tests for React code where I get the error
Unable to find an element by: [data-testid="primary-cta"]
I actually want this to be for negative test case where the button is not displayed in the page
const renewButton = getByTestId('primary-cta');
expect(renewButton).not.toBeInTheDocument();
So I am using "not.toBeInTheDocument();" , but I am getting the error
Can anyone pleaase help ?
Thanks in advance
You can use queryByTestId if the element may not be present. queryBy* methods return null if the element is not found.
getBy* methods throw errors in case there are no matching elements. Hence, the error you are getting.
Relevant docs: Link

test is failing to locate element and giving error "no such element: Unable to locate element"

I am trying to locate an element but it is giving me
"no such element: Unable to locate element".
My element is below link:
View
Xpath=//a[#href='/Admin/Company/View?id=225896']
Xpath=//*[contains(#href,'/Admin/Company/View?id=225896')]
Xpath=//*[contains(#href,'View?id=225896')]
and many more. How do I solve the problem?
use this.
//*[local-name()='a'][#href='/Admin/Company/View?id=225896']
Make sure that the element is not in an iframe otherwise you will have to switch to it before locating
Make sure that the element is not in the Shadow Dom otherwise you will have to locate the relevant ShadowRoot object first and then use relative locators from the ShadowRoot
Make sure that the element is present in the DOM by the time you're trying to find it, i.e. execute getPageSource() function and ensure that it's there as it might be the case you will need to go for Explicit Wait if the element is added to the DOM via i.e. AJAX call
And last but not the least, try locating the element by link text using View as the criteria
driver.findElement(By.linkText("View"))

protractor - issues with scrolling into infinite scroller

I have a protractor test looking for a record in my infinite scroller component like this.
searchPage.searchEntitlement('search criteria');
var myHiddenElementInScroller = element(by.repeater('result in ctrl.results track by $index').row(12));
browser.driver.executeScript(function () { arguments[0].scrollIntoView(); }, myHiddenElementInScroller .getWebElement());
myHiddenElementInScroller.click();
This is supposed to scroll to the element and click it. Instead its throwing me element not visible error.
Has anyone come across this situation? Any help greatly appreciated.
You might need to explicitly wait for the scrolling into view actually happen:
browser.driver.executeScript("arguments[0].scrollIntoView()", myHiddenElementInScroller.getWebElement()).then(function () {
myHiddenElementInScroller.click();
});
Or, with browser.actions():
browser.actions().mouseMove(myHiddenElementInScroller).click().perform();
In few scenarios the element which we are looking for will be covered with some other element from DOM.when protractor tries to click it,the click will be received by the element that covers the actual element. So in such situation you need to use native javascript click event. Look at the below code.
browser.executeScript("arguments[0].click()", myHiddenElementInScroller.getWebElement())
The above code will send a click event directly to the mentioned webElement even if it is visible or not.
NOTE: this is not the recommended way for clicking an element. but you can you this in scenarios where you have no other workaround to achieve the click event.
Thanks for all the responses. I was able to resolve this issue by using element(by.CssContainingText(cssSelector, searchText)) locator.

Angularjs Control the expand and collapse of an acordion

I am trying to understand how works the ui.bootstrap accordion in angularjs. In my case of use, I have three accordions of which only the first is allowed to open. The rest of them should not open when the user click on their header until an option is selected from the previous accordion.
Now, I am experimenting with a controller which shows a error message when the user click on the second and third accordeon and, after that, it close them. This is my Plunker with my code:
http://plnkr.co/edit/rSg6Az?p=preview
The part of the error message works fine but I can not get that the accordeon selected is closed when I click it.
Any idea?
Regards:
Adrian Ferreres
First I give you the thanks for your answer and my apologies for my delay to answer it. I didn't tested your solutions because I found two solutions which I like more than you told me. The first was given by Vanya Dineva in the official mail group of Angular:
Here's a couple of things you can try:
Notice the accordionGroup directive uses the collapse directive in its template (https://github.com/angular-ui/bootstrap/blob/master/template/accordion/accordion->group.html )
You can modify and instead of having collapse="!isOpen" you can replace the isOpen with a new variable that you would set to false until your condition is met
Notice the ng-click="toggleOpen()" in the accordion group template (https://github.com/angular-ui/bootstrap/blob/master/template/accordion/accordion-group.html ). Try creating a custom function e.g. ng-click="openIfConditionMet()" and put your logic inside the function
The second was found by myself. I add a modal window to show the error message when a user tries to open an accordion. In the function which closes the window I put the code to close the accordion:
http://plnkr.co/edit/rSg6Az?p=preview
You can use ng-class, and bind it to the value of the option in each previous accordion.
You can probaly warp your assignment to a $timeout but there is already in master the support for is-disabled. https://github.com/angular-ui/bootstrap/commit/9c43ae7c0a66ff454c97296122d8f82c89ac4d5e
You can either build it your self or wait for the next release :-)

Resources