To select dropdown value in selenium using name - selenium

Below is my code.
This is my combobox/dropdown box
<TR id="oldcontent" bgcolor="#D0D0D0">
<TD ALIGN="left" id="oldcontent">
<select name="status" style="width=150" id="newcontentformat">
<option value="15">Approved1</option>
<option value="16">Approved2</option>
<option value="17">Approved3</option>
</TD>
</TR>
how do i select the value Approved2?can anyone help me with the xpath?
I tried the below..but its not working
selenium.select("//select[#name='status']",Approved2);
selenium.select("status",Approved2);
Also i have multiple and and i need to select the combobox present in very first .
Thanks in Advance for help

The second parameter of the method has to be a string. Try:
selenium.select("//select[#name='status']", "Approved2");

Related

Setting selected attribute of an option based on property of outer v-for

I have a select inside a v-for. The options in the select is based on different data. I have tried many things, but cannot get the selected value properly set.
<tr v-for="(week,idx) in Picks">
<td>{{ week.start_formatted }}</td>
...
<template v-if="week.scenario==5">
<td>
<select>
<option v-for="tm in AvailableTeams" v-bind:value="tm.id" selected="{{tm.id === week.team_id}}">
{{ tm.name }}
</option>
</select>
</td>
<td></td>
</template>
...
</tr>
You need to add a colon(:) before selected. In VueJS, if u write an expression to set the value of an HTML attribute, u should use v-bind:<propName> or just :propName.
You already did it for v-bind:value, you just missed it for selected.
<option v-for="tm in AvailableTeams" v-bind:value="tm.id" :selected="{{tm.id === week.team_id}}">
{{ tm.name }}
</option>

Selenium - Selecting an item from dropdown list if the values are inside <table> tags and NOT under <option> in html

The below is a snippet from our html code which appears as a drop down list in the application. I am unable to select a particular value from the drop down list using Select class in Selenium - possibly because it doesn't have "Option" tags?. Is there any way to select the item?
-UPDATE: This has a parent tag which talks about visibility. Basically to tell that elements are visible only if the user clicks the drop down arrow.
"< input type="hidden" *****"
For e.g. I need to select 'I am option2' from the list during the test execution.
<div id="xyz" class="DropdownInnerContainer" style="z-index:99999;">
<table id="abc" class="DropdownItemContainer" list="1000020">
<tr class="">
<td value="" index="0" title="">
</td>
<td class="BorderCell"></td>
</tr>
<tr class="">
<td value="I am option1" index="1" plid="1002827">I am option1</td>
<td class="BorderCell"></td>
</tr>
<tr class="">
<td value="I am option2" index="2" plid="1002828">I am option2</td>
<td class="BorderCell"></td>
</tr>
<tr class="">
<td value="I am option3" index="3" plid="1002829">I am option3</td>
<td class="BorderCell"></td>
</tr>
<tr class="">
<td value="I am option4" index="4" plid="1002830">I am option4</td>
<td class="BorderCell"></td>
</tr>
</table>
If the text inside of the td that you want to select is unique, then you can click the table element with the id of 'abc' and then click the following element. The code provided is C#, but can be translated pretty easily.
IWebElement option = _driver.FindElement(By.XPath("//td[text()='I am option2']"));
It appears that since the drop down options were inside a < table >, the Select class was unable to identify the list options. So here's what I did:
First click() the dropdown, which opens up the menu:
driver.findElement(By.xpath(".//*[#id='abc01_tbl']/div/div")).click();
Then pass the value using the contains() method and then click() on it.
driver.findElement(By.xpath(".//*[#id='xyz01_tbl']/tbody/tr/td[1][contains(text(),'I am option2')]")).click();
You can not use Select in this scenario because there is no any select tag for dropdown. Drop down is under table body.
Please use below xpath for select option form drop down.
driver.findElement(By.xpath("//table[#id='abc']/tr[td[text()='your option text']]/td"));

Need help finding xpath of input field beside label

I have a dom structure like this
<tr class="">
<td class="labelCol requiredInput">
<label for="name_lastacc2" class="">
<span class="requiredMark">*</span>
Last Name</label>
</td>
<td class="dataCol col02">
<div class="requiredInput">
<div class="requiredBlock"></div>
<input id="name_lastacc2" maxlength="80" name="name_lastacc2" size="20" tabindex="3" type="text"></div>
</td>
<td class="labelCol">
<label for="00NG0000008Rybp">Business Ext.</label>
</td>
<td class="dataCol">
<input id="00NG0000008Rybp" maxlength="10" name="00NG0000008Rybp" size="20" tabindex="22" type="text"></td>
</tr>
I am trying to find the input box next to its label.
Eg:
Last Name: ________________
I have tried using xpath queries like
//label[contains(text(),'Last Name']/../following-sibling::*/div/input[#type='text']
but i get an [INVALID XPATH EXPRESSION] error. Where am i going wrong ?
Your path expression is missing the closing bracket of contains().
//label[contains(text(),'Last Name')]/../following-sibling::*/div/input[#type='text']
But that said, I do not think your path expression is correct now. Your expression will match any following sibling of the parent of label[contains(text(),'Last Name')]. What you want it to find is the input element that immediately follows.
The only reason your original expression only finds one input element is that the second one is nested inside one more div. But I do not think you should rely on that.
Instead, try:
//label[contains(.,'Last Name')]/following::input[1]
Then, the result is
<input id="name_lastacc2" maxlength="80" name="name_lastacc2" size="20" tabindex="3" type="text"/>

Selenium checkbox data driven - Checkbox has only target but no value

Im having difficulties parameterizing (data driven) checkboxes using Selenium IDE. When I record selecting a checkbox using Selenium i get the following action:
<tr>
<td>click</td>
<td>id=_ctl0_MainContentPlaceHolder_UseCaseBesturing__ctl1_dgOndersteundeChannels__ctl2_chkbxChannel</td>
<td></td>
In order to parameterize this action and pointing to my test data (XML) file I need a value which I can set as a variable. But in this action there is no value, only a target which is the ID.
Any ideas how to parameterize this action or how to check the checkbox using a value instead of using only the target (ID)?
P.S. Text fields work fine by putting "${Parametername}" in value field in Selenium for an action. The Parametername will then be my column name in my test data file.
Html code of the checkboxes:
<table class="detailgrid" cellspacing="0" border="0" id="_ctl0_MainContentPlaceHolder_UseCaseBesturing__ctl1_dgOndersteundeChannels" style="border-style:None;border-collapse:collapse;">
<tbody><tr>
<td style="width:20px;">
<span disabled="disabled"><input id="_ctl0_MainContentPlaceHolder_UseCaseBesturing__ctl1_dgOndersteundeChannels__ctl2_chkbxChannel" type="checkbox" name="_ctl0:MainContentPlaceHolder:UseCaseBesturing:_ctl1:dgOndersteundeChannels:_ctl2:chkbxChannel" checked="checked" disabled="disabled"></span>
</td><td>
<span id="_ctl0_MainContentPlaceHolder_UseCaseBesturing__ctl1_dgOndersteundeChannels__ctl2_lblChannelNaam">POS</span>
</td>
</tr><tr>
<td style="width:20px;">
<input id="_ctl0_MainContentPlaceHolder_UseCaseBesturing__ctl1_dgOndersteundeChannels__ctl3_chkbxChannel" type="checkbox" name="_ctl0:MainContentPlaceHolder:UseCaseBesturing:_ctl1:dgOndersteundeChannels:_ctl3:chkbxChannel">
</td><td>
<span id="_ctl0_MainContentPlaceHolder_UseCaseBesturing__ctl1_dgOndersteundeChannels__ctl3_lblChannelNaam">eCommerce</span>
</td>
</tr><tr>
<td>
<br>
<span type="checkbox"><input id="_ctl0_MainContentPlaceHolder_UseCaseBesturing__ctl1_dgOndersteundeChannels__ctl4_chkalles1" type="checkbox" name="_ctl0:MainContentPlaceHolder:UseCaseBesturing:_ctl1:dgOndersteundeChannels:_ctl4:chkalles1" onclick="CheckAll('chkbxChannel', this.checked);"></span>
</td><td>
<br>
Alles Aan
</td>
</tr>
</tbody></table>
Still use a click but change how you find the target by using xpath.
It would look something like this:
Target:
xpath=//td/span[text()='POS']
Hope this helps!
After going through the question, I tried using parameter for Target in the test step( as it was not possible to parameterize Action(Command) after various attempts) in Selenium IDE.
To select a checkbox the Xpath should point to the input tag and can be checked using click command.
IMO, as per the HTML, the correct Xpath for checking the checkbox corresponding to eCommerce should be :
//span[text()='eCommerce']/ancestor::td/preceding-sibling::td/input

Selenium select dropdown element using xpath string

I have quite specific problem regarding both selenium and xpath.
I have to make an automated tests based on scenarios using selenium. All pages are automatically generated and using Ids is impossible.
All form elements though are designed in same way.
<table>
<tr><td> Title </td></tr>
<tr><td> input/dropdown/etc </td></tr>
</table>
He is the specifics
<tr>
<td width="34%" valign="top" bgcolor="#ffffc7">
<span class="bold">Status wniosku</span>
<span>Test</span>
</td>
<td width="66%" bgcolor="#ffffc7">
<select id="ctl00_ContentPlaceHolder_2041" class="baseCtrl" name="ctl00$ContentPlaceHolder$2041">
<option value="" selected="selected">- wybierz -</option>
<option value="save">tylko zapisz</option>
<option value="pj">zapisz i wyślij do PJ</option>
</select>
<span>
</span>
<span id="ctl00_ContentPlaceHolder_ctl19" class="validation" style="display:none;">Określ status wniosku</span>
<span id="ctl00_ContentPlaceHolder_ctl20" class="validation" style="display:none;"></span>
<span></span>
</td>
</tr>
Using http://www.xmlme.com/XpathTool.aspx I have designed xpath for dropdown elements.
//span[text()='LABELNAME']/ancestor::*[1]/following-sibling::*/select/option[text()='TEXTVALUE']
I would like to use Selenium to click on the element i found.
I've tried Selenium.Click() and variations of Selenium.Select() but with no results.
My question is, is the xpath designed correctly? If so how should i execute it using Selenium? Thx for the help.
Try below xpath for selecting second option
"//span[text()='Test']/ancestor::*[1]/following-sibling::*/selec‌​t"
Ex:
Selenium.Select("//span[text()='Test']/ancestor::*[1]/following-sibling::*/selec‌​t","label=Save");