I have a html source in which several input boxes are defined as follows:
<div class="jupyter-widgets widget-hbox widget-text" style="">
<div class="widget-label" style="display: block;">Project:</div>
<input type="text" class="form-control" placeholder="">
</div>
<div class="jupyter-widgets widget-hbox widget-text" style="">
<div class="widget-label" style="display: block;">Title:</div>
<input type="text" class="form-control" placeholder="">
</div>
...
How do I select the input element associated with the Project element?
This should work:
//div[contains(text(), "Project")]/following-sibling::input
First part //div[contains(text(), "Project")] will find the div element which has "Project" in text attribute, then /following-sibling::input will find the input type sibling of that div element.
Read more about these xpath functions here.
You can use something like: "//input[#type='text'][1]" or "(//input[#type='text'])[1]". Respectively the number represents the element you are looking for. Hope it helps.
Related
I have problem table when i want set value with for each i.index get error java.lang.NumberFormatException: For input string: "${i.index}". In Array i need numer so ${i.index} is int. I dont know what i do wrong.
<div class="form-group row" th:each="attribute, i: ${attributeList}">
<label class="col-sm-3 col-form-label" th:text="${attribute.name}"></label>
<div class="col-sm-9">
<input type="text" th:field="*{technicalAttributes[${i.index}].name}" class="form-
control" placeholder="Nazwa">
</div>
</div>
You can't nest expressions (*{...${...}...}) like you're doing without using preprocessing. Your code should look like this:
<div class="form-group row" th:each="attribute, i: ${attributeList}">
<label class="col-sm-3 col-form-label" th:text="${attribute.name}"></label>
<div class="col-sm-9">
<input type="text" th:field="*{technicalAttributes[__${i.index}__].name}" class="form-control" placeholder="Nazwa">
</div>
</div>
(If you weren't using the th:field attribute, the expression *{technicalAttributes[i.index].name} would also be appropriate. But since you are using a th:field you have to use preprocessing.)
I have a xml like this and am trying to select the groupIdentifier element without the display:none child (would like to use the css "identifier" along with it) to finally select the input. Have been at this for hours and would like to call the xpath gods to help me out.
<div class="groupIdentifier">
<div>
<input class="inputClassIdentifier">
</div>
<div>
...
<div>
<div class="something">
... some more elements
</div>
<div class="identifier hidden" style="display: none">
... some more elements
</div>
<div class="something">
... some more elements
</div>
</div>
</div>
</div>
<div class="groupIdentifier">
<div>
<input class="inputClassIdentifier">
</div>
<div>
<div>
<div class="something">
... some more elements
</div>
<div class="identifier ">
... some more elements
</div>
</div>
</div>
</div>
Thanks
edit:
I have
//div[contains(#class, 'identifier') and not(contains(#style, 'display: none'))] which basically selects the identifier div of the second section.
What I need now is to select the input with class inputClassIdentifier within its parent.
Here's your xpath.
//div[#class='groupIdentifier' and div/div/div[not(contains(#style, 'display: none'))]]
I got it using descendant axis
//div[#data-testid='groupIdentifier' and descendant::div[contains(#class, 'identifier') and not(contains(#style, 'display: none'))]]//input[#name='inputClassIdentifier']
I'm trying to recognize two objects on two different UI using a dynamic xpath.
So object are as in snippet:
<div class="reports-filter">
<ul id="portfolio-input--temp-ddisable">
<li>
<h3 class='reportOptions'><label>Enter Account Number</label></h3>
<input id="name2" name="name2" type="text" value="" size="20"/>
</li>
</ul>
<input type="hidden" name="secure" value="true"/>
</div>
<div class="multiCol">
<h3 class='reportOptions'><label>Account Number </label></h3>
<input id="reportFilters17.typeSpecific.string" name="reportFilters[17].typeSpecific.string" class="textFilter" type="text" value=""/>
</div>
Now i tried used following xpath but to no luck
//h3[contains(text(),'Account Number$']
//h3[contains(.,'Account Number$']
//h3[#class='reportOptions']
//h3[#class='reportOptions']/text()
//label[contains(.,'Account Number$')]
.//*[contains(text(),'Account Number$')]
why are you using $ in contains function if you want to check end with number then use matches and second thing use //h3[#class='reportOptions']/label or //h3[#class='reportOptions']/label/text()
I would like to put check this checkbox with selenium in ruby programing.
but i can`t do put check. how should I do?
Now, I make below code.
# code
element = #driver.find_element(:xpath, '//*
[#id="lookCheck10"]/div[1]/div[2]/div[1]/label')
#driver.execute_script("arguments[0].click();", element);
# html
<div class="e-select-box p-look-bike__type-box">
<div class="e-title">
<input type="hidden" name="data[Reserve][types][10]"
id="lookCheck10_" value="0"/><input type="checkbox"
name="data[Reserve][types][10]" id="lookCheck10" value="1"
checked="checked"/> <label
for="lookCheck10">BIKE</label>
</div>
<div class="e-media">
<div class="e-media__body p-look-bike__type-detail">
<p>this is good for family</p>
</div>
<div class="e-media__image p-look-bike__type-image">
<img src="/images/reserve/img_biketype_10.jpg" alt="bike">
</div>
</div>
</div>
I am assuming you want to select a checkbox with label 'BIKE'. For that, use below code-
element = #driver.find_element(:xpath, '//*[#id="lookCheck10"]')
#driver.execute_script("arguments[0].click();", element);
Given that the HTML contains:
<div class="Animal">
<div class="radio">
<label>
<input type="radio" data-bind="checked: Animal"> Cat </label>
</div>
<div class="radio">
<label>
<input type="radio" data-bind="checked: Animal"> Dog </label>
</div>
How do we write the following expression in XPath:
Find the 2nd element in the radio button group where the data-bind attribute has a value of "checked: Animal"
I've been searching for a while and I can't come up with something that works. I tried for example:
//input[#data-bind='checked: Animal'][2]
but this always selects the first option.
//div[#class='radio'][2]//input[#data-bind='checked: Animal']
[1], [2], [3] work for elements that have the same parent