Unable to import data from excel for drop-down list - testing

Here is the code below,
driver.findElement(By.id("ctl00_ContentPlaceHolder1_cbpAssociationNew_panelAssnDetailAdd_Industry_B-1")).click();
driver.findElement(By.id("ctl00_ContentPlaceHolder1_cbpAssociationNew_panelAssnDetailAdd_Industry_I")).sendKeys(sh.getCell(2, 2).getContents());
i have tried out the below code still not working:
Select sel= new Select(driver. id( "ctl00_ContentPlaceHolder1_cbpAssociationNew_panelAssnDetailAdd_Industry_B-1" ));
sel.SelectByVisibleText(sh.getCell(2, 2).getContents());
For text field type it's working fine. Only for List fields it's not importing.
HTML CODE BELOW:-
<input type="text" style="color:#555555;font-family:Arial,Helvetica,sans-serif;cursor:default;" readonly="readonly" onkeypress="aspxEKeyPress('ctl00_ContentPlaceHolder1_cbpAssociationNew_panelAssnDetailAdd_Industry', event)" onfocus="aspxEGotFocus('ctl00_ContentPlaceHolder1_cbpAssociationNew_panelAssnDetailAdd_Industry')" onblur="aspxELostFocus('ctl00_ContentPlaceHolder1_cbpAssociationNew_panelAssnDetailAdd_Industry')" onchange="aspxETextChanged('ctl00_ContentPlaceHolder1_cbpAssociationNew_panelAssnDetailAdd_Industry')" id="ctl00_ContentPlaceHolder1_cbpAssociationNew_panelAssnDetailAdd_Industry_I" value="--Select--" name="ctl00$ContentPlaceHolder1$cbpAssociationNew$panelAssnDetailAdd$Industry" class="dxeEditArea dxeEditAreaSys " autocomplete="off">
HTML LINK:-
https://docs.google.com/document/d/1fZ-YuuYXlrJzFbRJ_oPOMycdMlloS66dPIYe6TJDfas/edit?usp=sharing

From what I can see from the HTML code snippet, this is not a simple Select dropdown that can be worked out using Select class. It consists of tables and table elements.
So, to resolve this you've to do things:
1- Click on the dropdown table using the below code:
driver.findElement(By.id("ctl00_ContentPlaceHolder1_cbpAssociationNew_panelAssnDetailAdd_Industry_I")).click();
2- Click on the dropdown item that matches the text so fetched from the sheet using below:
driver.findElement(By.xpath("//td[#class='dxeListBoxItem' and contains(text(),'"+sh.getCell(2,2).getContents()+"')]")).click();;
OR try using "Action class":-
1- Click on the dropdown table using the below code:
Actions act = new Actions(driver);
act.moveToElement(driver.findElement(By.id("ctl00_ContentPlaceHolder1_cbpAssociationNew_panelAssnDetailAdd_Industry_I"))).click().perform();
2- Click on the dropdown item that matches the text so fetched from the sheet using below:
act.moveToElement(driver.findElement(By.xpath("//td[#class='dxeListBoxItem' and contains(text(),'"+sh.getCell(2,2).getContents()+"')]"))).click().perform();

Related

How to get an export value of the radio button group in acroforms using javascript?

I am making a fillable pdf for a questionnaire in pdf. I have to use radio buttons in the questionnaire. I used the below code snippet to get the value of the radio button group, but it gives me either a null exception or return blank.
I tried a simple code in a blank pdf with just one group of radio buttons with two options and a button.
The code is shown below, where "Group1" refers to the radiobutton group:
var choiceVAL = this.getField("Group1").value; app.alert(choiceVAL);
On clicking the button, the code keeps giving me an exception. I checked all the forums, and this is the code snippet that is used everywhere. I have set the export value to "Y" and "N" respectively.
Can anyone help me with this??

Data-driven dropdown menu Katalon Automation Recorder

I'm trying to automate click with Selenium IDE. I was trying to figure out if I can use the "Select" command, but it didn't work.
I would like to click on the value on the dropdown that I put in my CSV file. Like I want a specific value of the dropdown for each line of my CS.
Here's the code.
Katalon [WebUI] Select is meant only to select default html select component. Yours is custom select box.
You need to select that exactly same way as you do manually like
Click the menu
Wait for dropdown to be visible
Select the particular value based on name from your csv
Based on your html, your Katalon script will be like this,
TestObject menu = new TestObject('Menu').addProperty('css', ConditionType.EQUALS, "div.md-select-menu-container")
WebUI.click(menu)
TestObject dropdownValue = new TestObject('DropDownValue').addProperty('xpath', ConditionType.EQUALS, "//md-option[contains(text(), 'AVAN - Advancè')]")
WebUI.waitForElementVisible(dropdownValue, 30)
WebUI.click(dropdownValue)

Clearing semantic ui multiselect dropdown when values are selected dynamically?

I am trying to load multiselect dropdown value based on click button action dynamically. When one click is performed value is selected and appended in the dropdown. But when I clicked next time, the dynamic values are appended to the previous value. So I decided to clear multiselect dropdown on each click.
But when values are selected dynamically, To clear dropdown
$('.ui.fluid.dropdown').dropdown('restore defaults');
$('.ui.fluid.dropdown').dropdown('clear');
Both also not working. Because of dynamic appending of data.
So my question is how to clear semantic mutiselect dropdown dynamically.
I tried to use the following code to clear the dropdown and it works fine.
var class_name = $('.ui.fluid.dropdown');
$(class_name).dropdown('clear');
$(class_name).dropdown('destroy');
$(class_name).dropdown('restore defaults');

Import from Excel using jxl.jar isn't working for List Values

I use jxl.jar for importing data from the exce. For Text Field type the import is working fine. But 'List Field Type' it isn't working. Can anyone pls help me out.
driver.findElement(By. id( "ctl00_ContentPlaceHolder1_cbpAssociationNew_panelAssnDetailAdd_SalutationName_I" )).sendKeys(sh.getCell(0, 1).getContents());
In the above image we have 'Industry' as List field type.
i Have tried with xpath also still i have the problem with that List Field type.
Looks like you are trying to send values to a "Select" dropdown. You should rather use the below code to set the value. Assuming the given id is for a dropdown and the getContents() returns an option to be selected from the dropdown:
Select sel = new Select(driver.findElement(By.id("ctl00_ContentPlaceHolder1_cbpAssociationNew_panelAssnDetailAdd_SalutationName_I")));
sel.selectByVisibleText(sh.getCell(0, 1).getContents());

Having issue in selecting drop down element under makemytrip website

Having issue in selecting drop down element under the following website
http://flights.makemytrip.com/makemytrip/fareCal.do?intid=NewHP_to_DF_FC_Menu
I'm unable to select any one of the cities listed below.
Please help me out resolving the same.
Scenarios Tried
driver.findElement(By.className("chzn-single")).click();
driver.findElement(By.xpath("//span[contains,'NewDelhi']")).click();
driver.findElement(By.xpath("//span[#id='fromcity_chzn']")).click();
This works:
WebElement leavingFrom = driver.findElement(By.xpath("//*[#id='fromcity_chzn']/a"));
WebElement goingTo = driver.findElement(By.xpath("//*[#id='tocity_chzn']/a"));
leavingFrom.click();
leavingFrom.sendKeys("Bangalore");
leavingFrom.sendKeys(Keys.RETURN);
goingTo.click();
goingTo.sendKeys("Goa");
goingTo.sendKeys(Keys.RETURN);
Here is working sample:
//First get main dropDowns
var leavingFromDropDown = driver.FindElement(By.Css("#fromcity_chzn"));
var goingToDropDown = driver.FindElement(By.Css("#tocity_chzn"));
//Select value from first dropDown using dropDown items index
//First click on dropDown to open it
leavingFromDropDown.click();
//Now find items in it and click on any item using it's index (also can be used method to access this elements using their names
leavingFromDropDown.FindElements(By.Css(".active-result"))[1].click();
//this dropDown closes automatically, but if not you need to click on it again to close
//Same perform with second element
goingToDropDown.click();
goingToDropDown.FindElements(By.Css(".active-result"))[2].click();
If you want to use input box to enter any value from DropDown you need to find that element and using sendKeys set it's value. E.g.:
leavingFromDropDown.click();
var input = leavingFromDropDown.FindElement(By.Css(".chzn-search > input"));
input.sendKeys('Goa');
input.sendKeys(Keys.Enter);//or tab