How to select by value using Chosen in dropdown?

I’m trying to select by value a Dropdown that uses Chosen and I’m not getting it, is there any hint for this?

image.png

You have highlighted a DIV element (which is obviously not a SELECT element). If you use selectOptionByValue on the SELECT element with id SupplierCategoryLevelOne and pass the value “MT” is should work.

You should paste your test code then it would be easier to construct the line of test code you need.

I tried using the selectByValue with the ID “SupplierCategoryLevelOne” of the Select and the Katalon did not find the value "MT ".

// Code:

WebUI.openBrowser(‘https://govdev.midassolutions.com.br/Mrv/DEV/portal/Supplier/Invite/CERTFOR’)

WebUI.maximizeWindow()

WebUI.delay(2)

WebUI.sendKeys(findTestObject(‘Object Repository/Login_Campos/Usuario_Login’), GlobalVariable.Login)

WebUI.sendKeys(findTestObject(‘Object Repository/Login_Campos/Usuario_Senha’), GlobalVariable.Senha)

WebUI.delay(2)

WebUI.click(findTestObject(‘Object Repository/Login_Campos/Botao_Entrar’))

WebUI.sendKeys(findTestObject(‘Object Repository/Certificacao_Juridica_Campos/CNPJ’), ‘18.272.616/0001-87’)

WebUI.click(findTestObject(‘Object Repository/Certificacao_Juridica_Campos/Email_do_Fornecedor’))

WebUI.delay(10)

WebUI.sendKeys(findTestObject(‘Object Repository/Certificacao_Juridica_Campos/Email_do_Fornecedor’), ‘lucas@lucas.com’)

// Here, the select works normally as it is a common Dropdown.

WebUI.selectOptionByValue(findTestObject(‘Object Repository/Certificacao_Juridica_Campos/Meio_de_Notificacao_Pedido_de_Compra’), ‘EMAIL’, false)

// Here is the error.

WebUI.selectOptionByValue(findTestObject(‘Object Repository/Certificacao_Juridica_Campos/Teste’), ‘MT’, false)

AAC.png

From what I understand, the < select Class (…) creates the < div class = "Chosen-container (…) So the options can be searched. And even trying to select the value by the parent type (< select Class (…)), the Katalon cannot search for the reason for creating the < div class = "Chosen-container (…).
I don’t know how to circumvent this :frowning:

I missed that the select has been hidden by the CSS style so the selectByValue is unable to target the element.

Your only option is to mimic what a user does - you cannot use selectByValue.

What does a user do?

The user opens the chosen as a dropdown, and can choose the option by searching manually or searching in the message box.

The user opens the chosen as a dropdown, and can choose the option by
searching manually or searching in the message box.

What is “the chosen” and what do you mean by “choose the option by searching manually”?

Understand I don’t know your application - what might seem obvious to you is a complete mystery to me.

Basically, if you know what element a user clicks on you need to target that in your test code. If you want more help, you need to show me the test code and show me a LOT MORE of the HTML.

@Russ Thomas, I managed to solve this problem by changing the Chosen to a common Dropdown.

And now you have some weird error, can you tell me if you have any wrong implementation of the groovy language in this code snippet?

WebUI.openBrowser('https://govdev.midassolutions.com.br/Mrv/DEV/portal/Supplier/ - Pastebin.com

Img2.png

1 - Your pastebin link goes to an error page.

2 - Java is not happy with the path(s) you supplied. Where? I don’t know, all you gave me was an error message.

Read this and PLEASE act on it:

1 Like

Code:

WebUI.openBrowser(‘https://govdev.midassolutions.com.br/Mrv/DEV/portal/Supplier/Invite/CERTFOR’)

WebUI.maximizeWindow()

WebUI.delay(2)

// Login

WebUI.sendKeys(findTestObject(‘Login_Campos/Usuario_Login’), GlobalVariable.Login)

WebUI.sendKeys(findTestObject(‘Login_Campos/Usuario_Senha’), GlobalVariable.Senha)

WebUI.delay(2)

WebUI.click(findTestObject(‘Login_Campos/Botao_Entrar’))

// Dados Gerais

TesData PlanilhaMRVCertJ = findTestData(‘Data Files/Certificacao_Juridica_Planilha/Dados_Planilha’)

for (int i = 1; i <= PlanilhaMRVCertJ.getRowNumbers(); i++)

{

WebUI.sendKeys(findTestObject(‘Object Repository/Certificacao_Juridica_Campos/CNPJ’), findTestData(‘Data Files/Certificacao_Juridica_Planilha/Dados_Planilha’).getValue(1, i))

WebUI.click(findTestObject(‘Certificacao_Juridica_Campos/Email_do_Fornecedor’))

WebUI.delay(10)

validaCNPJinvalido = WebUI.verifyTextPresent(‘CNPJ Informado é inválido.’, false)

validaCNPJandamento = WebUI.verifyTextPresent(‘Não é possível iniciar processo de certificação. Já existe um processo em andamento.’, false)

if (validaCNPJinvalido == true || validaCNPJandamento == true)

{

String path = WebUI.takeScreenshot()

WebUI.takeScreenshot(“C:\\Users\\lucas.ferreira\\Desktop\\DocLucas\\MRV_Katalon\\PrintScreenKatalon\\Print($i).png”)

WebUI.navigateToUrl(‘https://govdev.midassolutions.com.br/Mrv/DEV/portal/Supplier/Invite/CERTFOR’)

}

else if (validaCNPJinvalido == false && validaCNPJandamento == false)

{

WebUI.sendKeys(findTestObject(‘Object Repository/Certificacao_Juridica_Campos/Email_do_Fornecedor’), findTestData(‘Data Files/Certificacao_Juridica_Planilha/Dados_Planilha’).getValue(2, i))

WebUI.selectOptionByValue(findTestObject(‘Certificacao_Juridica_Campos/Meio_de_Notificacao_Pedido_de_Compra’), ‘EMAIL’, false)

WebUI.sendKeys(findTestObject(‘Certificacao_Juridica_Campos/Teste1’), ‘MT’)

WebUI.sendKeys(findTestObject(‘Object Repository/Certificacao_Juridica_Campos/Teste1’), Keys.chord(Keys.ENTER))

WebUI.navigateToUrl(‘https://govdev.midassolutions.com.br/Mrv/DEV/portal/Supplier/Invite/CERTFOR’)

}

}

1°:
Description Resource Path Location Type

Archive for required library: ‘C:/Program Files/Katalon_Studio_Windows_64-5.4.2/plugins/org.codehaus.groovy_2.4.7.xx-201611170128-e46/lib/org.apache.xerces.impl_2.11.0.jar’ in project ‘C%%Users%lucas.ferreira%Katalon Studio%MRV_Automation%MRV_Automation.prj’ cannot be read or is not a valid ZIP file C%%Users%lucas.ferreira%Katalon Studio%MRV_Automation%MRV_Automation.prj Build path Build Path Problem

2°:

Description Resource Path Location Type

The project cannot be built until build path errors are resolved C%%Users%lucas.ferreira%Katalon Studio%MRV_Automation%MRV_Automation.prj Unknown Java Problem