I'm using the "Auto click" chrome extension to automate a task.
With this extension I'm able to select a specific XPath that is going to be clicked.
I would need it to only click if the xpath next to it contains a specific text.
So imagine two buttons next to each other:
Button 1 xpath: //*[#id="ctl00_ContentMiddle_List1_View1_ctl03_Label4”]
Button 2 xpath: //*[#id="ctl00_ContentMiddle_List1_View1_ctl03_Button1”]
Button 1 contains the text "noclick"
Now I need to combine these two xpaths, so if Button 1 contains the text "noclick" then click Button 2
Am I on the right path with this? ->
//*[#id="ctl00_ContentMiddle_List1_View1_ctl03_Label4” and span[contains(text(),’noclick’)]]
Thanks for your help!
Marc
If the 1st expresision returns false (does not returns anything), Xpath will check the 2nd'
//*[#id="ctl00_ContentMiddle_List1_View1_ctl03_Label4”][not(contains(., "noclick")] ||
//*[#id="ctl00_ContentMiddle_List1_View1_ctl03_Button1”]
Related
As title says I am attempting to identify a new element that is added to a page after an add new button is clicked that shares an xpath the same as many other elements.
To give some background there is a list of items on the page. You can interact with the list in the following ways. Add New, Edit and Delete.
You can add a new row to the list. When you click add new you type in text to name the item in the list and then have the option to save or cancel.
The cancel element (new row) is the same as the delete element (existing row) in terms of xpath (except where it is on the list).
I can't use the specific list element because this is an automation script that would run everyday and the position on the list could change.
Any thought on what I could do to do identify the xpath of the new cancel button when add new is clicked.
The button itself does not contain words but is an image of a trashcan, so I can't use something like text to find a cancel button.
I saw some ways to add text to find by but the issue I'd run into is that a user could generate this new row at anytime.
Any thoughts would be helpful! :)
Thanks!
To identify the new cancel button, you can try and tweak (it's a wild guess) one the following XPath expressions :
If the trash is an image, we look for an element which child contains a #src attribute (the name of the image : trash.gif for example).
//*[./*[contains(#src,"trash.gif")]]
If the trash is an icon, we can search the same way as before (you need to identify the name of the icon) :
//*[./i[contains(#class,"trash")]]
URL: https://www.wakanow.com/en-ng/
Type mum in Flying from text box. It shows suggestions. I want to print all options but unable to find locator for the same because html is hiding on mouse click.
Please help.
You can right click on the parent element, id txt-modi-fly-from, and select "Break on ... Subtree modifications".
You'll find that when you enter 'mum' into the field, the javascript on page will freeze. Keep pressing the Resume button on the far right until your expected entries are visible.
It appears you can do a findElement by ID 'txt-modi-fly-from_dropdown', then findElements by classname 'angucomplete-row'.
I am trying to automate a booking process from an airline site.
In the second page of the booking process ('Select Flights'), there are multiple radio buttons which are very similar with other radio buttons available in the page. How can I select the radio button that I want to click?
I have already tried the xpath of the radio button but to no avail.
Here is the html code of the radio button:
Screenshot from booking.airasia.com
Please advise. Thank you
First element
Second Element
Well its true that you are getting similar elements for that given xpath but you also have to go through their siblings/parents etc for different scenarios.
Here is the xpath I tried that identified the individual elements that you were looking for, are depicted above.
//div[#class='iradio_square-green']/input[#id='trip_0_date_0_flight_0_fare_0']/following-sibling::ins
For others radio buttons you just have to change the flight number.
Hope this helps...
:)
I'm trying to complete a happy path e-commerce payment test but I cant seem to click on the nested element for credit card to be honest I'm not entirely sure which is the clickable element.
Any help to get this working would be appreciated.
When inputting forms, you typically want to interact with input and select elements. In this case, you can see that the visible input field is a radio button - ie <input type="radio">.
You access radio buttons using the radio method and select it by using the set method:
browser.radio(id: 'cc-payment').set
The element you want to click is the input with type radio. You should be able to do something like:
driver.find_element(:css, "input[id='cc-payment'][value='creditCard']").click
I'm curious if clicking on the parent item would resolve.
#browser.input(id: 'cc-payment').parent.click
If the div registers the click and sets the input then this might work. You should be able to manually verify this beahviour by clicking outside of the radial and seeing if it selects.
I'm trying to write some automated tests for this site https://www.jigsaw-online.com/basket/viewbasket
I'm trying to write a test to add or remove qty from a specific item added to the basket page.
I'm having trouble writing xpath that will get me the element for a button where the link contains some value in the href.
Take the add qty button for example this will be get me all the buttons on page
//button//i[#class='fa fa-plus']
This will get me all the items in the basket__items class where the link contains the product I am wanting to add qty to
//ul[#class='basket__items']//a[contains(#href,'12')]
I'm just having trouble combining these two pieces of xpath to get me the add qty button for the product I want to add too.
Can someone help me with this?
This is one possible way to combine the two XPath expressions (formatted for readability) :
//li[
contains(#class,'basket__row')
and
.//a[contains(#href,'12')]
]
//button//i[#class='fa fa-plus']
Explanation :
Basically, the XPath starts off with //li[contains(#class,'basket__row')], expression that select individual basket item row.
and .//a[contains(#href,'12')] in predicate narrow down the result to specific basket item row that you're interested in.
from this point, it is straightforward to incorporate your first XPath //button//i[#class='fa fa-plus'], which will return the button from the selected basket item row