How can we extract value by using xpth or css selector if the attribute is dynamically changed for example:
<p data-reactid=".2e46q6vkxnc.1.$0">
<b data-reactid=".2e46q6vkxnc.1.$0.0">Mark Obtain</b>
<i class="avu-full-width" data-reactid=".2e46q6vkxnc.1.$0.1">
<span data-reactid=".2e46q6vkxnc.1.$0.1.0"> </span>
<span data-reactid=".2e46q6vkxnc.1.$0.1.1">450 A+.</span>
</i>
</p>
<p data-reactid=".2e46q6vkxnc.1.$1">
<b data-reactid=".2e46q6vkxnc.1.$1.0">Student Name</b>
<i class="avu-full-width" data-reactid=".2e46q6vkxnc.1.$1.1">
<span data-reactid=".2e46q6vkxnc.1.$0.1.0"> </span>
<span data-reactid=".2e46q6vkxnc.1.$0.1.1">First Name</span>
</i>
</p>
In this case attribute of element is dynamically changing but "Mark Obtain" and "Student Name" will always be same, so is there any way or can we write if condition or some regex along with xpath expression to get "450 A+" and "First Name" values.
Please help
To get required values you can use below XPath expressions:
//p[b="Mark Obtain"]//span[2]/text()
to get "450 A+."
and
//p[b="Student Name"]//span[2]/text()
to get "First Name"
Related
Here is my code for that
can anyone please help me on this
<div class="location has-feedback ph-a11y-location" data-ph-at-id="location" data-ph-id="ph-default-1648705629687-ph-event-search-v1qkzjzs-MYIYtj">
<label for="hasfeature-location" id="hasFeature-search-location-label" data-ph-id="ph-default-1648705629687-ph-event-search-v1qkzjzs-y9rfkd">
<ppc-content key="HdNSNY-qkzjzs-ph-event-search-v1-default-searchLocationText" data-ph-at-id="label-text" data-ph-id="ph-default-1648705629687-ph-event-search-v1qkzjzs-DFwDbG">
Search location
</ppc-content>
</label>
<!-- autocomplete="location" -->
<input type="text" ref="locationbox" ph-a11y-autocomplete="is-show-results-on-focus.bind: !isNewEventLocationSearch" name="location" aria-controls="loc-listbox" value.bind="formData['location'].value" id="hasfeature-location" aria-owns="loc-listbox" aria-haspopup="listbox" class="form-control location ph-a11y-location-box au-target" placeholder="City,State,Country" key-placeholder="aQgj4W-qkzjzs-ph-event-search-v1-default-locationsearchboxplaceholderText" data-ph-at-id="input" aria-labelledby="hasFeature-search-location-label" data-ph-id="ph-default-1648705629687-ph-event-search-v1qkzjzs-7ChQ5X" au-target-id="49" aria-activedescendant="">
<span aria-hidden="true" show.bind="!formData['location'].value" data-ph-id="ph-default-1648705629687-ph-event-search-v1qkzjzs-0TiVEf" class="au-target icon icon-map-pin form-control-feedback location-icon" au-target-id="50"></span>
<button aria-label="Clear text" type="button" key-aria-label="RHJ2eO-qkzjzs-ph-event-search-v1-default-clearLocationText" class="form-control-feedback phs-keysearch-clear location-clear-icon au-target aurelia-hide" data-ph-at-id="clear-eventsearch-link" click.delegate="clearFieldValue('location', locationbox)" show.bind="formData['location'].value" data-ph-id="ph-default-1648705629687-ph-event-search-v1qkzjzs-LLyYrP" au-target-id="51">
<i class="icon icon-cancel" aria-hidden="true" data-ph-id="ph-default-1648705629687-ph-event-search-v1qkzjzs-ln6ufj"></i>
<span class="sr-only" data-ph-id="ph-default-1648705629687-ph-event-search-v1qkzjzs-hKDCAz">
<ppc-content key="SivoXp-qkzjzs-ph-event-search-v1-default-locationMenuOpenClearText" data-ph-at-id="clear-eventsearch-text" data-ph-id="ph-default-1648705629687-ph-event-search-v1qkzjzs-ELD0zf">
location clear text
</ppc-content>
</span>
</button>
<ul class="on-focus location phs-location-suggested-list au-target aurelia-hide" id="loc-listbox" aria-labelledby="loc-listbox" aria-label="locations" role="listbox" tabindex="-1" show.bind="fieldData.location.showListbox" data-ph-at-id="suggested-data-list" data-ph-id="ph-default-1648705629687-ph-event-search-v1qkzjzs-THexzy" au-target-id="52" data-ol-has-click-handler="" aria-expanded="false">
<!--anchor-->
<li ref="facetRef" data-ph-at-id="no-data" data-ph-id="ph-default-1648705629687-ph-event-search-v1qkzjzs-DzgLbR" class="au-target" au-target-id="56">
<div class="no-facet-results" data-ph-id="ph-default-1648705629687-ph-event-search-v1qkzjzs-bf6eoG">
<span data-ph-id="ph-default-1648705629687-ph-event-search-v1qkzjzs-RRGnuz">
<ppc-content key="wApLmD-qkzjzs-ph-event-search-v1-default-noLocationResultsFound" data-ph-at-id="no-data-text" data-ph-id="ph-default-1648705629687-ph-event-search-v1qkzjzs-g9TfpZ">
No results found
</ppc-content>
</span>
</div>
</li><!--anchor-->
</ul>
</div>
Not sure why Jaws announcing back slash and it is happening in palceholder text
I think this is a bug in JAWS where JAWS might be double-escaping your comma characters in the <input> placeholder text when there is an aria-labelledby or aria-label associated with the <input>.
So, instead of reading it as "City,State,Country" it instead escapes the commas twice and reads it as "City\,State\,Country".
I recommend that you remove the commas in your placeholder text to avoid the JAWS error. An alternative would be to put the placeholder text outside of the <input> (such as below the input field as help text) and associate it using the aria-describedby attribute. For example:
<label for="location" id="search-location-label">Search location</label>
<input type="text" name="location" id="location" aria-labelledby="search-location-label" aria-describedby="location-helptext">
<span id="location-helptext">City, State, Country</span>
In the application I am working on, we can add the following markup for the pictured result
<span class="cell-inner-undefined">
<span title='Not defined' class="status pl-undefined" ></span>
</span>
Inside the relevant CSS we have the following:
.pl-undefined:before {
content: "";
color:#969696;
}
The item assigned to content looks like unicode. Instead of that I want to get the result of the following:
<span class="fa-stack fa-5x">
<i class="fa fa-info-circle fa-stack-1x" style="color:blue" ></i>
<i class="fa fa-ban fa-stack-1x" style="color:red"></i>
</span>
How can I get the class 'pl-undefined' to return the FA icon generated above?
p.s: Adding the fa span in my page displays the desired icon, but I need it to be displayed using the class.
I didn't find any other way of achieving this, other than adding a javascript which will find a <span class="cell-inner-undefined"> and replace it with the fa CSS
I have the following type of element,
<td class="x-btn-mc">
<em id="ext-gen141" class="x-btn-split" unselectable="on">
<button id="ext-gen33" class=" x-btn-text" type="button">
<div class="mruIcon"/>
<span>Legacy CaseMon</span>
</button>
</em>
</td>
In this I am unable to select exact co-ordinates of drop down arrow,
And the xpath for all the list of options are also same( <//*[#id='ext-gen141']> )
Only thing varies is Span (Say I have to select "Cases",then span value becomes <Span>Cases</Span>)
Can anyone please help me choosing the different value
Thanks..
In a custom step in cucumber, I wrote this:
find(:xpath ,"//ul//input[#placeholder = 'Enter Something'][last()]").set(value)
And Im getting Regexp ambiguous match error:It is getting both the elements.
How can I get this element using xpath(or maybe even css) in cucumber??
I'm using cucumber-1.2.1 and capybara-2.0.3
(Please note:every attribute in the above two input fields are same)
HTML:
<ul class = "someclass">
<li>
<div>
<a></a>
<input></input>
<input placeholder = "Enter Something"></input>
</div>
</li>
<li>
<div>
<a></a>
<input></input>
<input placeholder = "Enter Something"> // This is the element I want
</input>
</div>
</li>
</ul>
You'll need an extra set of parenthesis in your xpath:
"(//ul//input[#placeholder = 'Enter Something'])[last()]"
Both these buttons have almost similar ID (the number on the ID may change and so is not reliable)
Both have same classes
They both reside under the same parent
Except for the span nothing is different
All the UI elements of the application I am trying to locate and build events on Using Selenium are similar to the below piece...
Can anyone please suggest how I can locate these buttons preferable with xpath?
<div id="button-1749" class="x-btn x-box-item x-toolbar-item x-btn-default-toolbar- small x-noicon x-btn-noicon x-btn-default-toolbar-small-noicon x-item-disabled x-disabled x-btn-disabled x-btn-default-toolbar-small-disabled" style="margin: 0pt; left: 1563px; top: 0px;">
<em id="button-1749-btnWrap" class="">
<button id="button-1749-btnEl" class="x-btn-center" autocomplete="off" role="button" hidefocus="true" type="button" aria-disabled="true" disabled="">
<span id="button-1749-btnInnerEl" class="x-btn-inner" style="">Delete Selected</span>
<span id="button-1749-btnIconEl" class="x-btn-icon x-hide-display"> </span>
</button>
</em>
</div>
<div id="button-1750" class="x-btn x-box-item x-toolbar-item x-btn-default-toolbar-small x-noicon x-btn-noicon x-btn-default-toolbar-small-noicon" style="margin: 0pt; left: 1654px; top: 0px;">
<em id="button-1750-btnWrap" class="">
<button id="button-1750-btnEl" class="x-btn-center" autocomplete="off" role="button" tabindex="1" hidefocus="true" type="button">
<span id="button-1750-btnInnerEl" class="x-btn-inner" style="">New Title</span>
<span id="button-1750-btnIconEl" class="x-btn-icon x-hide-display"> </span>
</button>
</em>
</div>
If you want to look for the elements under a specific div, you can use descendent axis.
Example:
//div[#id='your div']/descendant::button[contains(#class, 'x-btn-center')]/span[text()='Delete Selected']"
This will give you Deleted Selected button that is within the div with id 'your div'.
You could also use GetElements (opposed to GetElement) and this will return a List of elements that match your search criteria. Then, providing the order the buttons appear on the page never changes, you may use this List to access the button you want every time by using the associated index.
Eg.
ReadOnlyCollection<IWebElement> buttons = driver.FindElements(By.XPath("YOUR XPATH HERE"));
//If it's the 3rd button that matches your criteria
buttons[2].Click(); //or whatever you want with this button :)
I think this should work in your case:
locator = driver.find_element_by_xpath("//div/em/button/span[contains(text(),'Delete Selected')]")
You can do similar way in case of another element.
though xpath is a desired locator per your question, there are documented speed differences between xpath and css selector, here's one example: http://saucelabs.com/blog/index.php/2011/05/why-css-locators-are-the-way-to-go-vs-xpath/. to locate those elements via css selector, use the following, python example
els = driver.find_elements_by_css_selector("button[id^=button]
for eachel in els:
eachel.click()
You have to create your own xpath if the xpath of 2 elements are same
driver.findElement(By.xpath("//span[contains(text),'New Title')]")).click;