Not able to select list item in a drop down field by text


#1

In my application, I am not not able to select a particular list item by text value.

WebUI.scrollToElement(‘Object Repository/Page_NewTitle/li_Raheja Geeta’, 3)

In the above statement, instead of selecting mentioned name, different value gets selected.


#2

scrollToElement() does not perform selections.

Would you like to share the rest of your code along with an explanation of what you’re trying to achieve?


#3

/Call Login Test Case
WebUI.callTestCase(findTestCase(‘ONIX_SB/0001_Login’), [(‘AppURL’) : ‘a’], FailureHandling.STOP_ON_FAILURE)
WebUI.delay(5)

//Mouse hover Proposals menu
WebUI.mouseOver(findTestObject(‘Object Repository/Page_Product Admin/span_Proposals’))

//Click on Propose a Title link
WebUI.click(findTestObject(‘Object Repository/Page_Product Admin/span_Propose a Title’))
WebUI.delay(5)

//Click on Create a New Title link
WebUI.click(findTestObject(‘Object Repository/Page_Propose a Title/a_Create a New Title’))
WebUI.delay(5)

//Date date = new Date();

//Enter Title

WebUI.setText(findTestObject(‘Page_NewTitle/input_Title’), findTestData(“TestData”).getValue(“Title”,1))
WebUI.delay(2)

//Enter Short Title
WebUI.setText(findTestObject(‘Page_NewTitle/input_Short_Title’), findTestData(“TestData”).getValue(“ShortTitle”,1))
WebUI.delay(2)

//Select Authored
WebUI.click(findTestObject(‘Page_NewTitle/input_AuthoredEdited’))
WebUI.delay(5)

// Select Publisher
WebUI.click(findTestObject(‘Page_NewTitle/input_Publisher’))
WebUI.click(findTestObject(‘Page_NewTitle/li_SAGE Publications Ltd’))
WebUI.delay(5)

//Select Signing Editor

AcqEditor = findTestData(“TestData”).getValue(“AcqEd”, 1)

WebUI.click(findTestObject(‘Object Repository/Page_NewTitle/input_Editor’))
WebUI.click(findTestObject(‘Object Repository/Page_NewTitle/div_AcqEd’))
WebUI.delay(2)
WebUI.scrollToElement(‘Object Repository/Page_NewTitle/li_Raheja Geeta’, 3)
//WebUI.click(findTestObject(‘Object Repository/Page_NewTitle/div_AcqEd’))
//String ulSelector = findTestObject(‘Object Repository/Page_NewTitle/div_AcqEd’).findPropertyValue(‘xpath’)
//String liSelector = ulSelector + findTestObject(‘Object Repository/Page_NewTitle/li_AutomationQA’).findPropertyValue(‘xpath’)

WebUI.delay(5)

//Select Target Pub Dt
WebUI.click(findTestObject(‘Page_NewTitle/input__EstPubMonth’))
WebUI.scrollToElement(findTestObject(‘Page_NewTitle/li_05’), 5)
WebUI.click(findTestObject(‘Page_NewTitle/li_05’))

WebUI.click(findTestObject(‘Page_NewTitle/input_EstPubYear’))
WebUI.delay(8)
WebUI.click(findTestObject(‘Page_NewTitle/li_2020’))
WebUI.delay(5)

//Click on Add button
WebUI.click(findTestObject(‘Page_NewTitle/btn_Save’))


#4

In the above code in following step, where I am trying to
//Select Signing Editor

Its a list of drop down, and I need to select specific value which I can in fact select from test data sheet
but here selectby is not working and the values are identified as list values, I am not sure how to resolve this, as I have lot many dropdown fields like this in my application


#5

So finding a good solution is important.

I think (I’m guessing) the list elements are stored in the td-element below the input-element you highlighted. Can you open that td and send a screenshot? If they are not in that td, they must be stored somewhere else. You need to find them so we can see them.

In your code, what you need to do is click the dropdown element. Then I would try focusing the target list element and/or clicking it. But we’re not there yet… get me the screenshot so I can see what’s going on.


#6

Thanks Thomas…
This is the screenshot when I clicked on a list element, its getting s


The full expath for the Editor dropdown:
/html/body/form/div[8]/table[2]/tbody/tr[2]/td[3]/table[1]/tbody/tr[7]/td/table/tbody/tr[6]/td[4]/div/input

The selector value found:
#ctl00_ctl00_SmartMasterContent_TitleProposalContent_dlPublisher_ClientState

The Xpath
//*[@id=“ctl00_ctl00_SmartMasterContent_TitleProposalContent_dlEditor_ClientState”]

On changing any value in dropdown, the xpath is not getting changed, though i can find the li value for each separately

value displayed in Katalon xpath selector:
//div[@id=‘ctl00_ctl00_SmartMasterContent_TitleProposalContent_dlEditor_DropDown’]/div/ul/li[2]


#7

No, I expected a capture of the the elements in the dropdown.

which tells me the HTML is a <ul> element containing a bunch of <li> elements. Please take a screenshot of those elements.


#8


is there any other way to connect for quick resolution, I need to complete this script today please


#9

No there isn’t another way. The speed of resolution is unfortunately down to two things:

  1. The accuracy of your responses to my questions.
  2. The time I have available to help you. >90% of us are doing this for free while we are trying to do our own work.

So, please be patient.

The problem here is exacerbated by your lack of knowledge of the makeup of your page. For example, this input control is HIDDEN - notice the type="hidden" attribute:

Twice you have posted screenshots of that element when in fact it is of no interest, as far as i can tell. But since you highlighted it, I spent valuable time trying to figure out how it could possibly be involved.

So, based on what I see from your last post, I think you want to click on this element:
image

Then click on the <li> / list item you require. If that involves scrolling, it might be better to use keys instead of clicks. But first you need to get that dropdown to appear.

Word of advice: You obviously know how to open DevTools since you’re using it to capture screenshots. Now you need to learn how to find what’s relevant by tracking the HTML in the DOM and highlighting the correct elements. Highlighting the wrong element doesn’t help. Drawing red boxes around the wrong element doesn’t help. Please, learn to use DevTools properly. Then perhaps you would find a solution much quicker.


#10

hey I asked the different way to connect because I was of the same impression that I am not able to explain the problem correctly in technical terms, and I was having the same idea that I might be increasing the time to get the problem solved and eating your time as well.

I am a manual tester, and just trying to learn Katalon by direct hands on as per the current project demand without any training.
I am not able to find any post or tutorial on handling li elements
Could you please help on how use keys to scroll instead of click and if you can direct me to the relevant post/video.

Thanks


#11

@ThanhTo Can you help here? I need to hit the sack and get some sleep…


#12

I’ve read the conversation and still are unsure of the exact element you’re trying to click on. From what I can understand, you want to click (select, but I think a click would suffice in this case) on a list item with different text depending on the requirement.

The following is a generic tutorial, aiming to help you to click on an element when you know that element contains a text, and that this text needs to be changed per requirement

First, in your script where you need to do click on the list item, write the following line:

// Text of the item that you want to click on
def textOfThisItem = 'katalon'
// Notice findTestObject is taking two things: ID of the test object, and a map containing the text you want to click on
WebUI.click(findTestObject('Object Repository/item_has_text_that_needs_to_be_clicked_on', ['textVariable': textOfThisItem]))

At this point, the Test Object does not exist yet, which is why you need to manually create a blank Test Object called item_has_text_that_needs_to_be_clicked_on right under Repository folder.

If you notice in the above code, the findTestObject is accepting the second argument which at this point does not make sense yet. However, intuition should tell you that the passed in value will be used somehow.

The next thing you need to do is to specify the following XPath into the newly created Test Object.

Pay attention to $ since it is a must. The locator itself doesn’t make sense, because ${textVariable} is not a valid XPath syntax. However when this Test Object is used in execution, Katalon will replace ${textVariable} with the value passed in the second argument of findTestObject.

Both ${textVariable} and the value which will actually be used katalon are present in the code above, I believe your intuition would help connect the ideas.

When the line of code above is executed, the final locator would be:

//*[contains(text(), 'katalon)]

which selects an element that contains the text “katalon”. Then this element will be clicked on by WebUi.click.

To confirm this, you can write this after the above piece of code:

println findTestObject('Object Repository/item_has_text_that_needs_to_be_clicked_on, 
['textVariable': textOfThisItem]).getSelectorCollection()
.get(SelectorMethod.XPATH);

(Ctrl + Shift + O for auto imports)

which will print //*[contains(text(), 'katalon')] to the console log. I include this because you may want to trial and error the XPath to your element, for which printing our the XPath will be helpful. You can compare the expected XPath against what is printed to see if it maches your expectation.

References

The practice of using $ in your Test Object is called Test Object Parameterization (parameterization means you use variables instead of hard-coded values). Documentation here (Mobile in the title is irrelevant, it is also applicable to Web): https://docs.katalon.com/katalon-studio/docs/parameterize-mobile-test-object-properties.html#in-manual-view


#13

Thanks a lot, I will try