XPath - get a button inside another element with class - xpath

I need to find a button element using XPath. The problem is, the button has no unique identifier like Id or name, but is located inside another element which has a unique class (i.e. a class that no other element on page uses). I know how to get to that element and identify it by class but I don't know how to access the button inside that element.
.//mat-header-cell[#class='mat-header-cell cdk-column-delete mat-column-delete ng-star-inserted']
Any suggestions?

SOLUTION I FOUND:
Just added '//button' to the end of xpath and it works now!
.//mat-header-cell[#class='mat-header-cell cdk-column-delete mat-column-delete ng-star-inserted']//button

Related

XPath 'list' object has no attribute 'click'

I'm trying to select a checkbox on the following public webpage using Selenium XPath from Python and click it to change the checked status.
http://simbad.u-strasbg.fr/simbad/sim-fout
For example, the checkbox that I would like to click is located under "Fluxes/Magnitudes" and is named "U".
Upon inspection of this page I built the following XPath to select the checkbox:
//*[#type ='checkbox' and #name='U']
This returns what I believe to be the correct element, however when I try to run click() on the object it fails with the exception 'list' object has no attribute 'click'
When I look at the functions for this object in a debugger it indeed does not have a click function. How can this be true for a checkbox? Is there a different element that has to be selected?
Thanks!
You didn't paste your code here, but from the error you getting it's quite clear, that you are using
driver.find_elements_by_xpath('//*[#type ='checkbox' and #name='U']')
instead of
driver.find_element_by_xpath('//*[#type ='checkbox' and #name='U']')
find_elements_by_xpath method returns a list of web elements. You can apply click() method only on a single element, that's why you should use
driver.find_element_by_xpath('//*[#type ='checkbox' and #name='U']')
or alternatively
driver.find_elements_by_xpath('//*[#type ='checkbox' and #name='U']')[0]
to get the first (single) element from the returned list

how to find visibility of element / image in calabash

I am working on calabash android with the platform ruby.
And I have to find the visibility of an element / image and it has id and as well only one property ie., enabled , that too always true.
and i tried the options isVisible , isDislayed but am not sure these properties exists
First try this command
query("*")
If it shows element, then proceed with getting element using ID.
query("* css:'#id_name'")
The above line will display all the element with ID=id_name.
Note: It will show only visible element.
If you need to get all element(visible/hidden), you need use this code:
query("* all css:'#id_name'")

How to find specific text field with same id?

I am testing this one angularjs application that has
text_field(:date, :id => 'transfer_date')
Problem is that there are two text fields with this id the reason being that the first one has ng-show = externalaccount and the second has ng-show = !externalaccount.
So when I test something that is not externalaccount, I will receive an error saying that the text_field is not visible. However when I test externalaccount, the test will pass fine. I looked around and found
Page-object gem: Identifying object with same properties based on their visibility
I tried this but it there are other text_fields on the page. I need to find the first visible text_field that has id='transfer_date'. How do I set this up with pageobject or step definitions?
You can find the first visible text field with specific attributes using:
text_field(:date){ text_field_elements(:id => 'transfer_date').find(&:visible?) }
This says to find all text fields with the specific id and then from that list find the first that is visible.

AJAX Page Loader navigation bar

My site is:
http://econrespuestas.com.ar
And i'm having trouble with AJAX page loader integration. When you click on a link in "secondary-menu", it adds it the "current-menu-item" class, but it doesn't remove de "current-menu-item" class from the other ones.
I'm trying to do it with this code:
// highlight the current menu item
jQuery('secondary-menu li').each(function() {
jQuery('thiss').removeClass('current-menu-item');
});
jQuery(thiss).parents('li').addClass('current-menu-item');
but it isn't working. There must be something wrong with the removeClass selector. Could you help me?
Firstly, thiss doesn't exist (unless declared somewhere else). It must be this. In addition try something more like...
jQuery('.current-menu-item').removeClass('current-menu-item');
jQuery(this).parents('li').addClass('current-menu-item');
This is saying "Remove the class current-menu-item from any objects with the class current-menu-item, then add the class current-menu-item to the parent li of the clicked item"
In addition, make sure that in your CSS, .current-menu-item{...} appears after any styling for the non-currently selected item.
See Fiddle: http://jsfiddle.net/6hR9K/2/
Also, unless you have a specific conflict with using the $ sign in place of jQuery, I suggest doing exactly that.
$('.current-menu-item').removeClass('current-menu-item');
$(this).parents('li').addClass('current-menu-item');

Is there a way to select a child element inside another child element in Watin

I am trying to select a link/button inside of a form, that is in a div. the way it was made is that there are two links/buttons of the same id, name etc. however they are in different forms, so the code i wanted to use is:
_myTest.Form(Find.ById("PermissionsForm")).Child(Find.ByClass("saveBtn")).Child(Find.ByText("SAVE"));
any help would be appreciated
I think this is what you need:
var button = _myTest.Form("PermissionsForm").Button(Find.ByClass("saveBtn"));
This will lookup the button having the class 'saveBtn' inside the form 'permissionsform' in your browser instance _myTest.
Have a look at this page to decide if you need to have .Button(..) or .Link(...) based on the html tag that is used in your html.
How about building a regex for the element?
Regex could something like this
Regex elementRe = new Regex("id=LnkOk href="http://stackoverflow.com");
Then you can use your code to Click this link. The Click method can be extended to accept Regex if it is not already doing that.
Let me know how this goes or if you need more info.
Cheers,
DM

Resources