Katalon Studio: WebUI.verifyElementText not seeing the text in an element - testing

I am trying to write a test case in Katalon Studio that will attempt to verify the contents of various fields against expected values. I am using the WebUI.verifyElementText() function to do this. I know that the element is being found (I verified in the Katalon debugger), but it fails the test indicating that the expected and actual values do not match. Below is the typical call I'm making:
WebUI.verifyElementText(findTestObject('SC_Elements/InitServiceInfo/service_name'), 'Task Allocation')
When the test case is run, it fails with an error like the following:
Test Cases/SC_Import/Verify_Import FAILED because (of) Verify element text of test object 'Object Repository/SC_Elements/InitServiceInfo/service_name' FAILED. (Root cause: Actual text '' and expected text 'Task Allocation' of test object 'Object Repository/SC_Elements/InitServiceInfo/service_name' are NOT matched.)
I don't understand why this is failing? Any ideas?

Your error says
Test Cases/SC_Import/Verify_Import FAILED because (of) Verify element text of test object 'Object Repository/SC_Elements/InitServiceInfo/service_name' FAILED. (Root cause: Actual text '' and expected text 'Task Allocation' of test object 'Object Repository/SC_Elements/InitServiceInfo/service_name' are NOT matched.)
that the actual text of the test object is ''.
So, try using WebUI.getAttribute(findTestObject('SC_Elements/InitServiceInfo/service_name'), 'value') and then comparing it to wanted text:
def testText = WebUI.getAttribute(findTestObject('SC_Elements/InitServiceInfo/service_name'), 'value')
WebUI.verifyMatch(testText, 'Task Allocation', false)

Could you paste the html and screenshot of the element. Sometimes the text visible in Web is not actual text, it can be stored in 'value' attribute. In this case, you have to get the attribute value and make the comparison on this value.

Related

How do I iterate through verifying different texts on a page in Robot Framework?

I've got a functioning Robot Framework test that checks for different texts on a page. It's pretty basic. Scans the page for a specific string, then logs a PASS/FAIL if the string is found. Here's my code.
Test Keyword
${p1}= Run Keyword And Return Status Page Should Contain Element xpath=//*[contains(text(), "A")]
Run Keyword If ${p1} Log To Console "(A) Present" ELSE Log To Console "(A) Not Present"
${p2}= Run Keyword And Return Status Page Should Contain Element xpath=//*[contains(text(), "B")]
Run Keyword If ${p2} Log To Console "(B) Present" ELSE Log To Console "(B) Not Present"
${p3}= Run Keyword And Return Status Page Should Contain Element xpath=//*[contains(text(), "C")]
Run Keyword If ${p3} Log To Console "(C) Present" ELSE Log To Console "(C) Not Present"
This runs perfectly fine, but I'm having trouble making this into a list. Or maybe an array? I'm not sure.
Do I make the xpaths variables inside of the list? Would I make the Run Keyword If statements their own keyword and then just pass those? I'm not sure. Please let me know where I'm going wrong here. Thanks!
What you have in the sample is a repetition of the same code with only one variable - and that is always a good candidate for a loop. This way you'll just pass a different value, doing the same checks.
FOR ${a} IN A B C
${p}= Run Keyword And Return Status Page Should Contain Element xpath=//*[contains(text(), "${a}")]
IF ${p} Log To Console "(${a}) Present" ELSE Log To Console "(${a}) Not Present"
END
If the values you're checking are more (or dynamic) and it's not convenient to list them as the looped over, you could put them in a list, and iterate over it:
${values}= Create List A B C
FOR ${a} IN #{values}
# the same code follows here

InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression contains(text() error message

I'm getting this error message when selenium/C# program tried to click on an element in a drop down list in Dynamis365.
Inner Exception 1:
InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression contains(text(), 'Submitted') because of the following error:
TypeError: Failed to execute 'evaluate' on 'Document': The result is not a node set, and therefore cannot be converted to the desired type.
(Session info: chrome=87.0.4280.88)
My Code is:
internal void SetValues()
{
findByElement.FindByXPath("//span[contains(text(), 'Submission Pending')]").Click();
findByElement.FindByXPath("contains(text(), 'Submitted')").Click();
}
The HTML is:
<span id="id-bc19d003-2d6a-43ad-8e1b-566ecbb00647-132-statuscode6-statuscode.fieldControl-pickliststatus-comboBox_text-value" class=" ">Submission Pending</span>
I'm trying to click on Submitted choice, which do not show in HTML:DropDownList
Note: The other drop down list choices do not show in html. Only after making a choice (Submitted) it shows up in the html (replaces Submission Pending")
Submission Pending
Submitted clicked
Are you sure the page has fully loaded? Have you read the docs, specifically the 'waits' section (link below for the python version). I had this problem and simply put a 5 second delay into the code and it worked fine.
https://selenium-python.readthedocs.io/waits.html
Alternatively you may find it easier locating the element by id rather than by XPath
FindByXPath("contains(text(), 'Submitted')")
This is not a valid XPath expression! All XPath must start with the slash / character. Perhaps you meant something like:
FindByXPath("//*[contains(text(), 'Submitted')]")
Below line of code worked:
findByElement.FindByXPath("//*[./text()='Submitted']").Click();

Selenium script getting error 'value cannot be null parameter: source' after setting password textbox

I am getting an error "Value cannot be null,parameter name: s" after setting password through selenium script and clicking submit button.
Please help me on this, Thanks
Am using the below code for setting password
var passwordtxt=driver.FindElement(By.Id("txtpassword"));
var JSexecutor= (IJavaScriptExecutor)driver;
JSexecutor.ExecuteScript("arguments[0].setAttribute('value', arguments[1])",passwordtxt,"mypassword");
Based on the error message you provided, it sounds like the item passwordtxt doesn't exist on the page. Value cannot be null is referring to the element you pass into ExecuteScript, which is passwordtxt in this case.
To solve this problem, you will need to change the way you are finding passwordtxt. If you post some more HTML from your page's source, we can help you determine the correct selector to use.

How to resolve "Using 'Get Element Attribute' without explicit attribute is deprecated" in robot framework using selenium library

This works and returns exactly what I want:
*** Variables ***
${HOME_LOGO}= css=#header > nav > div.header-gutter > div > img
*** Keywords ***
Home logo is visible
Element Should Be Visible ${HOME_LOGO}
${logo_src}= Get Element Attribute ${HOME_LOGO}#src
log ${logo_src}
However, I am getting a WARN when I run it: Using 'Get Element Attribute' without explicit attribute is deprecated
I have tried several approaches, but have not been able to resolve the warn message AND get the information I want into ${logo_src}. I am looking for the img src.
What is the best way to either handle the warn or get the img src from the element in the xpath?
Thank you - I'm very new to robot framework and selenium but not new to test automation. Also new to stackoverflow.
They have changed how this keyword works from when it was originally designed. Instead of appending the attribute to the locator, provide it as an argument:
${logo_src}= Get Element Attribute ${HOME_LOGO} src
(note: there needs to be two or more spaces before src)

How do i scroll down to an element in Katalon?

I am unable to scroll down to the save button at the end of the page. Have tried using scrollToElement function but it does not work.
The error given :
Test Cases/merchantAdd1 FAILED because (of) groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.scrollToElement() is applicable for argument types: (com.kms.katalon.core.testobject.TestObject)
This doesn't necessarily mean you are unable to scroll to an element. You are missing a parameter.
The error message is saying you are trying to pass the wrong types of argument to scrollToElement() function. It is expecting a TestObject and an int (timeout in seconds) and you are passing in only the test object.
It should be something like
WebUI.scrollToElement(findTestObject('your test object'), 3)
If you are unable to find Test Object, and it is at the bottom of the page, try scrolling to position high absisse and ordinate.
for example WebUI.scrollToPosition(9999999, 9999999)
Then try click on the Objct