I need to check if there is a word or phrase on the page and get:
1.true or false
2.the name or xpath of the object containing
I need to check if there is a word or phrase on the page and get:
1.true or false
2.the name or xpath of the object containing
For #1 you can do the following in JavaScript:
document.body.innerText.includes("your text here")
Or, if the DOM API police are watchingâŠ
document.querySelector("body").innerText.includes("your text here")
But for #2 youâll need a dedicated dom-walker, I believe.
You want to make a Test Object with selector by XPath:
//body
Once this XPath expression is applied to a web page http://demoaut.katalon.com , it returns such a String value:
CURA Healthcare
Home
Login
CURA Healthcare Service
We Care About Your Health
Make Appointment
CURA Healthcare Service
Atlanta 550 Pharr Road NE Suite 525
Atlanta, GA 30305
(678) 813-1KMS
info@katalon.com
Copyright © CURA Healthcare Service 2018
On the other hand, you want to make a Test Case with following script codes:
WebUI.openBrowser('')
WebUI.navigateToUrl('http://demoaut.katalon.com/')
def content = WebUI.getText(findTestObject('Page_Cura Healthcare Service/body'))
WebUI.verifyMatch(content, '.*Make Appointment.*', true)
WebUI.closeBrowser()
The Regular Expression here
.*Make Appointment.*
matches with âMake Appointmentâ preceded with zero-or-more any characters and appended with zero-or-more any characters
By this, you can determine â1. true or falseâ if a string âMake Appointmentâ appears in the page.
----
You raised another problem:
2.the name or xpath of the object containing
I think that you can not solve this problem using the Katalon Studioâs standard keywords. All of the Katalon keywords assumes that you are aware which HTML node is of your interest in a page.
If you want to do HTML node-tree traversal, I think you need to develop a custom keyword which performs serious DOM traversal and transformation.
thx a lot)))
Try using WebUI.verifyTextPresent()âŠmake sure to set the FailureHandling.OPTIONAL tag if you want to use this in an if statement.
Below example of capture returning message when the login button was clicked.
This helps in capturing text on the page which can be include in any point within the test cases.
import com.kms.katalon.core.webui.driver.DriverFactory
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.openqa.selenium.WebDriver
WebUI.openBrowser(ââ)
WebUI.navigateToUrl(âhttps://semantic-ui.com/examples/login.htmlâ)
WebDriver wd =DriverFactory.getWebDriver()
WebUI.click(findTestObject(âObject Repository/Page_Login Example - Semantic/div_Loginâ))
String pageSource=wd.getPageSource()
Document doc = Jsoup.parse(pageSource);
String allText = ââ;
elements = doc.body().select("*");
for (Element element : elements) {
allText+=element.ownText()+"\n";
}
Hello to everyone,
For the first step, what about using the function WebUI.verifyTextPresent()
? Yesterday, I use the solution give into the third message into a custom keyword but at the end, to use this function you donât need to know where is the element right?