Xpath for dynamic select menus - selenium

I'm trying to automate some web testing using Kantu and Selenium. The page is using pq-select ParamQuery to generate select menus, but neither Kantu or Selenium can see them in the page.
I'm guessing my best bet is to use xpath to locate them, but I'm not too sure on how to do that. The HTML for the select menu is:
<td style="white-space: nowrap " aria-describedby="df230254-d8a5-4ba1-9950-58d26145d5a9" role="gridcell" data-container-for="section1" id="sectiongrid_active_cell" class="">
If I could use the data-container-for that would be the best I think, but I'm not sure how to get that via xpath.

As per the HTML you have shared you can use either of the following solutions:
XPath - 1:
//td[#id='sectiongrid_active_cell' and #data-container-for='section1']
XPath - 2:
//td[#id='sectiongrid_active_cell' and #data-container-for='section1'][#role='gridcell']
Note: The element is a ParamQuery select element which is being converted to theme ready jQueryUI widget, you have to induce WebDriverWait for the element to be visible/interactable.

Related

Ember dropdown selenium xpath

How to write xpath for the ember dropdown.
<ul id="ember-power-select-options-ember2473" class="ember-power-select-options ember-view" aria-controls="ember-power-select-trigger-ember2473" role="listbox"> <li class="ember-power-select-option" aria-selected="false" aria-current="false" data-option-index="0" role="option">Option A
Since the ember id changes, how can i write xpath??
With xpath:
//ul[contains(#id, 'ember-power-select-options-ember')]
With css:
ul[id*='ember-power-select-options-ember']
Other css:
ul.ember-power-select-options[role=listbox]
The value of the value of the id attribute will keep changing dynamically, everytime you access the AUT(Application Under Test). Hence to interact / click the dropdown you need to construct dynamic Locator Strategies as follows:
cssSelector:
ul.ember-power-select-options.ember-view[id^='ember-power-select-options-ember']
xpath:
//ul[starts-with(#id, 'ember-power-select-options-ember') and #class='ember-power-select-options ember-view']
References
You can find a couple of relevant detailed discussions in:
How to click on the ember.js enabled button using Selenium and Python
Selenium - Finding element based on ember

xpath: find element with attribute AND contains?

I am writing selenium tests, and I need to switch to an iframe with no id or name and which parent element contains variable id's (so not helpful. Also, the src attribute has variable data in it as well, so I can't target it directly like By.cssSelector("iframe[src='example']"). I need an xpath selector that targets the src, but also that uses contains. I am trying to learn how to build xpaths outside of Chrome's Copy XPath but I can't figure this one out. Thanks for your help! Here is the iframe html:
<iframe scrolling="auto"
src="/admin/catalog/manage_variants_in_product.jsp?productId=160502"
width="100%" height="100%" frameborder="no"
style="position:absolute; top:0px; left:0px;">
</iframe>
The "contains" CSS selector might help here:
iframe[src*=manage_variants_in_product]
FYI, there are also ^= and $= that mean "starts with" and "ends with" respectively.
The better way I would recommend to learn building xpath or csspath is Firepath add-on of Firefox
First install Firebug in your Firefox browse and then install Firepath.
There you will get the efficient way to get the xpath or evaluate the xpath build by yourself

picking element in firebug for use in selenium

Any idea how to select an element using Selenium and this output i Firebug:
<tr class="ui-widget-content ui-datatable-even ui-datatable-selectable" aria-selected="false" role="row" data-rk="0101" data-ri="0">
Use Chrome, lots easier. Locate the element, then open context menu with right click, Copy -> XPath. Tutorial with images: How to verify an XPath expression in Chrome Developers tool or Firefox's Firebug?
Use Firepath plugin for Firefox, which is add-on with dependency of Firebug
You can evaluate both XPATH & cssSelectors.

How To Write Selenium Xpath

I am stuck here. I am trying a write Xpath for the following. I am trying to click "Browse". The ID is changing every time.
I have tried this as my Xpath:
//*[#id='ext-gen43']/em/span/span
<a id="ext-gen43" class="x-tab-right" href="#">
<em class="x-tab-left">
<span class="x-tab-strip-inner">
<span class="x-tab-strip-text ">Browse</span>
</span>
</em>
</a>
XPATH WRITING PLUGINS :
Inorder to write xpath's by yourself you must first install firebug
and firepath plugins, they are the plugins available for Firefox
browser.
You can also install xpath checker which is another plugin available for firefox. It's a awesome plugin because you can actually
see the UI elements in the xpath checker as you are writing the
xpath.
EXAMPLE :
Inorder to write xpath's by yourself you must following the child and parent hierarchy available in the HTML tab in firebug.
STEPS :
Hover on the element you want to write xpath for using the small blue arrow available in the firebug toolbar in the top left corner.
Now click on the element, you would observe that the tag for the respective element in the firebug is highlighted.
Say your tag looks like :-
<label> class="control-label col-sm-3" for="name"> Your Name <label>
So the xpath for respective tag would be :-
//label[#class="control-label col-sm-3"]
So the above xpath specifies //parent tag which is label and into the bracket we should specify the locator, locator can be id, class, name anything.
And in your case the xpath would be :-
//span[#class="x-tab-strip-text"]
Have You tried copy xpath for given element in your browser(check element -> copy xpath)?
Then delete id and check once again.
It should be easy if you know how to select element by xpath with given class.
Try to use firepath to get xpath. It`s addon for FireFox https://addons.mozilla.org/uk/firefox/addon/firepath/

Can Python selenium be used to click on webpage labels?

I am working on third party applications where on the page too many labels are used as link or navigate to another page. So does python can do such tasks or read the page select list values?
I am using python 2.7 and selenium.
EDIT
There is a label called configuration see the corresponding code below:
<td class="tabtext-unsel"><nobr>Configuration</nobr></td>
<td class="unselected_tab_mid"><img src="/simpletrade/default/images/background/spacer.gif" width="16" height="25"></td>
Thanks,
Yes, it can. A label is implemented in HTML as <LABEL FOR="field_id">label text</LABEL>, and you can use it in an XPath locator in Selenium.
(Update after edit of question)
That's not a label in HTML, but it's still possible using an XPath locator. It's not even particularly difficult. Both <TD> elements are children of the same <TR> element, so something like this will do the job: //tr[td/a[.='Configuration']]/td/img will match the <IMG> element. But if all you want to do is locate the link, it's even easier: //tr/td/a[.='Configuration']