Nightwatch.js - assert.containsText I'm looking for a string but got empty (null) - nightwatch.js

Here is a spinet of my code:
browser
.waitForElementPresent('(//*[#class="textsize-xlarge"])[1]',5000)
.assert.containsText('(//*[#class="textsize-xlarge"])[1]', 'TEST-69554083978')
I want to verify that an element has a string using assert.containsText().
So I'm trying to check if the class textsize-xlarge contains text
"TEST-69554083978"
Visually I can see that it does but nightwatch returns an error message saying expected
"TEST-69554083978" got ""
Can anyone please tell me what I'm doing wrong here and point me in the right directions?

browser.useXpath(); // xpath will be used as the locating strategy so
all the selectors you pass should be xpath selectors
browser.useCss(); // switches back to css selector locator should be
your xpath
let locator = "[#class='textsize-xlarge']//*[contains(text(),'TEST-69554083978')]";
// Please modify above locator as I am not aware of your DOM but I can help further if you need any help in Xpath
return browser
.useXpath()
.waitForElementPresent(locator)
.assert.elementPresent(locator);
you can learn about node assertions: Node Assertions

Related

How to validate Browser Error's message with cypress

For example if user dont fill this field and press "continue" button, this error message will pop up.
I wonder is there a way with Cypress that I check that error message was displayed?
Kind regards
You can make this assert : cy.get('input:invalid').should('have.length', 1)
See https://github.com/cypress-io/cypress-documentation/pull/1919/files how to assert the validation message
I know this is an older question but here is another solution.
cy.get(`[data-testid="XXXX"]`)
.invoke('prop', 'validationMessage')
.should((text: string) => {
expect(text).to.contain(YYYY);
});
Using the above code here is what happens:
You grab the input / textarea element using cy.get Note: it is recommended to use a data-testid or obtain the element by something less brittle so the test doesn't fail if the text changes etc.
Using the invoke method, you can check validationMessage against prop then then, obtain the inner text and use expect to check if it's valid. This is very handy if you use custom validation messages.

HP UFT - WebElement cannot be found even after using correct xpath

I am new to UFT. I have a long "complex" xpath that finds precisely one element in chrome browser developer tools. When I use the same xpath in uft, the tool complains that the xpath is not in the object repository. Why does this happen and how do I fix it ?
This is what the xpath looks like:
//div[#class='a b c']//div[#class='p-q r-s']//div[#class='m n']//button[contains(text(), 'yes')]
I have to use such complex xpath because there are no ID attributes in this part of the page or any other 1-2 attributes which can uniquely identify the element.
Please help.
EDIT: My Vbscript code looks similar to this code:
Dim aButtonLoc
aButtonLoc = "//div[#class='a-b c-d-e g']" & _
"//div[#class='p-q r-s-t']//div[#class='uv w-x']" & _
"//button[contains(text(), 'Yes')]"
Error message: The {full xpath here} object was not found in the Object Repository. Check the Object Repository to confirm that the object exists or to find the correct name for the object.
There is an error in my aButtonLoc locator. It should have xpath mentioned, like this: aButtonLoc = "xpath:=//d...etc."

SOAP UI: how to use property in xpath match assertion

i am testing a WS that adds events for an user. the last event added has an userEventId incremented, so i don't know in advance its value. to recover it, i use a Property Transfer.
Now, i would like to use an xquery match assertion to test my value. But i don't know how to use my property in the equery expression.
this matches:
//events[last()]/userEventId = <userEventId>12</userEventId>
returns:
<xml-fragment>true</xml-fragment>
but this not:
//events[last()]/userEventId = <userEventId>${UserEventId}</userEventId>
returns:
<xml-fragment>false</xml-fragment>
Is there a solution?
I think you need something like:
//events[last()]/userEventId = <userEventId>${#TestCase#UserEventId}</userEventId>
${UserEventId} by itself will not expand to anything in SoapUI.
works using XPath Match assertion:
matches(//events[last()]/userEventId, '${#subscribe_one_event_TestCase#user_event_id}')
returns true.

Selenium WebDriver issue with By.cssSelector

I have an element whose html is like :
<div class="gwt-Label textNoStyle textNoWrap titlePanelGrayDiagonal-Text">Announcements</div>
I want to check the presence of this element. So I am doing something like :
WebDriver driver = new FirefoxDriver(profile);
driver.findElement(By.cssSelector(".titlePanelGrayDiagonal-Text"));
But its not able to evaluate the CSSSelector.
Even I tried like :
By.cssSelector("gwt-Label.textNoStyle.textNoWrap.titlePanelGrayDiagonal-Text")
tried with this as well :
By.cssSelector("div.textNoWrap.titlePanelGrayDiagonal-Text")
Note : titlePanelGrayDiagonal-Text class is used by only this element in the whole page. So its unique.
Contains pseudo selector I can not use.
I want to identify only with css class.
Versions: Selenium 2.9 WebDriver
Firefox 5.0
When using Webdriver you want to use W3C standard css selectors not sizzle selectors like you may be used to using in jquery. In your example you would want to use:
driver.findElement(By.cssSelector("div[class='titlePanelGrayDiagonal-Text']"));
From reading over your post what you should do since that class is unique is just do a FindElement(By.ClassName("titlePanelGrayDiagonal-Text"));
Also the CssSelector doesn't handle the contains keyword it was something that the w3 talked about but never added.
I haven't used css selectors, but this is the xpath selector I would use:
"xpath=//div[#class='gwt-Label textNoStyle textNoWrap titlePanelGrayDiagonal-Text']"
The css selector should then probably be something like
"css=div[class='gwt-Label textNoStyle textNoWrap titlePanelGrayDiagonal-Text']"
Source: http://release.seleniumhq.org/selenium-remote-control/0.9.2/doc/dotnet/Selenium.html
Did you ever tried following code,
By.cssSelector("div#gwt-Label.textNoStyle.textNoWrap.titlePanelGrayDiagonal-Text");
I believe using a wildcard in CSS would be more helpful. Something as follows
driver.findElement(By.cssSelector("div[class$='titlePanelGrayDiagonal-Text']");
This will look into the class attribute and see what that attribute is ending with. Since your class attribute is ending with "titlePanelGrayDiagonal-Text" string, the added '$' in the css statement will find the element and then you can perform whatever action you're trying to perform.

xpath locator not work as expected to locate a "<a" element with compound class name

This line will not work but I think I have used correct xpath?
driver.findElement(By.xpath("//a[contains(#class,'cke_button_bold')]")).click();
to locate a button like below :
<a id="cke_73" class="cke_off cke_button_bold">
id is a dynamic number so can be used as fixed locator here. And class is a compound class which is not supported by WebDriver findElement method...
I created simple html file and your xpath works with FirefoxDriver in WebDriver 2.1.0.
Also you can try to use
driver.findElement(By.className("cke_button_bold"))
Classname is supported by webdriver Api
Step 1:
Find the CSS Selector
Possible CSS Selectors here:
css=a[id*='cke']
css=.cke_off cke_button_bold
The above can be used Or Already we are having the method .ClassName But for avoiding duplication of Elements and Ambiguity we can use CSS Selector.

Resources