Confirm Element and go to next tag - selenium

I got some List with different Elements and every Element had it's one delete button. I want to delete a certain Element, so at first i need to confirm the Element (the Element contains: Test 1, Test2) and subsequently delete the Element
<div class="html-replace-container">
<form id="new_supplier_assignment" class="new_supplier_assignment" action="/supplier_assignments" accept-charset="UTF-8" method="post">
<h3 class="supplier-assignment-header progress-active">
Test 1
-
Test 2
</h3>
<a class="btn btn-danger btn-sm" data-replace-html-container="true" data-confirm="Sind Sie sich sicher?" style="float: right" rel="nofollow" data-method="delete" href="/supplier_assignments/122?owner=Customer">Löschen</a>
I've got this so fare :
<tr>
<td>click</td>
<td>xpath=//*[#id='new_supplier_assignment']/..//*[contains(text(), 'Test 1')]/../*[contains(text(), 'Test 2')]</td>
<td></td>
</tr>
I want to go to <a class="btn btn-danger ...> and click.
I can not use count() or indexof().

First find a h3 which first a is Test 1 and second a is Test 2, then use following-sibling::a to get the delete button
xpath: //h3[a[1][text()="Test 1"] and a[2][text()="Test 2"]]/following-sibling::a
In case you don't care which a is Test 1, it maybe the first or second a, If so, remove the index [1] and [2] , try below xpath:
//h3[a[text()="Test 1"] and a[text()="Test 2"]]/following-sibling::a

You can use the text as a locator:
driver.findelement(by.xpath("//a[contains(text(), 'YOUR TEXT')]")).click()
The different between the buttons is the text 'Test 1' 'Test 2' so you can locate the element and delete it by his text.

Related

xpath with Multiple condition in Selenium

Wants to locate element with multiple condition on particular row,
I want to Click on div which contains ng-click="condition001" which has parent link contains Auto-001
So query become like : Select element xpath("//div[contains(#ng-click,'condition001')]") where Link("Auto-001")
<tr ng-repeat="(abc, xyz)" ng-show="data.length > 0">
<td class="x001">
<div class="x002">
<a class="x003" href="#">Auto-001</a>
</div>
</td>
<td class="x004">
<div class="x005">
<div class="x006">
<div class="x007" ng-click="condition001" tabindex="0">
<i class="x008"></i>
</div>
</div>
</div>
</td>
</tr>
Please suggest relevant xpath code which can work for above criteria,
To click on the WebElement identified through xpath as ("//div[contains(#ng-click,'condition001')]") where it has partialLinkText as ("Auto-001") you can use the following line of Java code :
WebElement myElem = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[#class='x003' and contains(.,'Auto-001')]//following::td[1]//div[#class='x007' and #ng-click='condition001']")));

selenium xpath to select following-sibling

I have the following HTML:
<tr class="k-grouping-row" role="row">
<td aria-expanded="true" colspan="6">
<p class="k-reset">
<a class="k-icon k-i-collapse" tabindex="-1" href="#"></a>
<span class="consolidation-group" style="font-weight: bold;" data-key="aedfdb66-bb11-4350-9d25-21941820141b">jhmfgjf (2 Items)</span>
</p>
<a class="k-button unconsolidation-link" onclick="UnConsolidateGroup("aedfdb66-bb11-4350-9d25-21941820141b", "8780f45d-0e81-4f5c-b206-61b682b27d67")" title="Unconsolidate all matter entries in this group">
<span class="marginRight5 icon-unlink"></span>
Unconsolidate All
</a>
</td>
I would like to click on the span "Unconsolidate All" using following-sibling operator. I tried the following code:
//span[contains(text(), 'jhmfgjf')]/../following-sibling::class[#title='Unconsolidate all matter entries in this group']
But it does not work, the first part does work, it's just the following-sibling part that does not work.
Any help would be helpful
The element's name is <a>, not <class>.
You should do the following:
//span[contains(text(), 'jhmfgjf')]/../following-sibling::a[#title='Unconsolidate all matter entries in this group']
Unconsolidate All is not a span element. Its a "a" element.
You can use
//a[contains(text(),'Unconsolidate All')]
And if you specifically want to use following-sibling , you can use in this way
//span[contains(text(), 'jhmfgjf')]//following-sibling::a[#title='Unconsolidate all matter entries in this group']
For reference and learning about sibling, ancestors in xpath , you can see click here

capybara /cucumber can't find radio

I'm having an issue finding a radio button. Here is a snippet of the html:
<form action="/" id="frm-info" method="post"><input id="ClickedButton" name="ClickedButton" type="hidden" value="" /><input name="__RequestVerificationToken" type="hidden" value="KTQF3bkKPP0OirvtL1EYsW-Q77zq-8H9YAPqeoBB9ewpNSYoc0dOEout26qrtMmX6xBx0_roxqWRwCXAlwZRTyW9ZBTBjwNgifWqws6hyOFIRmc6O-7P6jZXbZNYJ5Pazt9Hmg2" /> <div class="row borGreyPad mlmrcolor bb0">
<div class="col-sm-12 coverImage">
<div class="col-md-7 col-lg-6 fr xs-fl">
<div class="frm-content axaborderBlue mt10">
<div class="pl25 pt15 pr15 pb10">
<p class="large-heading">Enter some basic information to get started</p>
<div class="row ">
<div class="row pl15">
<div class="col-sm-4 r xs-l mb5 f14">Application Taken: *</div>
<div class="col-sm-8 mb5">
<div class="groupBox">
<span class="dib f14 ">
<input id="ApplicationTaken" name="ApplicationTaken" tabindex="1" type="radio" value="ApplicationInPerson" /><span class="dib mr10 ">In Person</span>
</span>
<span class="dib f14 ">
<input id="ApplicationTaken" name="ApplicationTaken" tabindex="2" type="radio" value="ApplicationByPhone" /><span class="dib mr10 ">By Phone</span>
</span>
</div>
I want to select the radio button with name "ApplicationTaken" and value "ApplicationInPerson"
I've tried several different ways including:
When I click on the radio with name
"([^"]*)" and value "([^"]*)"$/ do |myName, myValue|
choose("#{myName}", :option => "#{myValue}")
end
and
When I click on the radio with name
"([^"]*)" and value "([^"]*)"$/ do |myName, myValue|
find(:xpath, "//input[#value='#{ myValue }']", match: :first).set(true)
end
I keep seeing the following error:
"Unable to find radio button "ApplicationTaken" with value "ApplicationInPerson".
I've also tried by ID, no luck. I CAN select a button on this page and fill in text fields, I just can't select radio buttons or drop downs. Thanks
Since you're using capybara try:
choose('Visible Text')
See:
https://gist.github.com/zhengjia/428105
For starters, you have two radio buttons with the same id. This is bad - you should not have duplicate ids on a page. Attempting to find an element by ID when there are duplicates is very unpredictable.
What's most likely happening is that it's finding the first element with a matching ID, and then checking the value attribute. When that doesnt match, it says the element could not be found, because it does not continue onto the next matching ID (because of the way id selectors work internally)
I see you're also using xpath to find the element. You generally should be using CSS instead of xpath for finding your elements.
So leaving the ID out, and using CSS instead, find('input[name=ApplicationTaken][value= ApplicationInPerson]') should get you the element you're looking for.

Selenium, XPATH to search for an Element in a table and Click on Radio button

I need to select an Item from the list of Table entries and click on Radio button. Radio button is on the left.
In the HTML Code below
Only Unique ID to look for a selection is the "TestSucscription"
I need to grep for this Value in the Table(It can have multiple Rows and It can be in any position) and then click on the Radio button on to its left.
<tr>
<td>
<input class="" type="radio" value="2ba068ff-b797-444e-b56b-a0ae0ae06f06" name="subscription[id]">
<div class="hide"></div>
</td>
<td> TestSubscription</td>
<td></td>
<td>Testing</td>
</tr>
<tr>
<td>
<input class="" type="radio" value="36a87684-9a65-4455-8605-dc5b5368fc23" name="subscription[id]">
<div class="hide">
<span class="error error-msg">This cannot be left blank.</span>
</div>
</td>
<td>SecurityProtection</td>
<td></td>
<td>CPN ChildProtection CPN ChildProtection</td>
</tr>
Please help me with this. I have tried below options in Webdriver(Java)
driver.findElement(By.xpath("//td[contains(text(), 'TestSubscription')]]/td/input[#type='radio']")).click();
I think Im going down the tree and coming back to click on Radio button which is why Its failing.
You can find the radio button with the following xpath:
//td[contains(text(), 'TestSubscription')]/../td/input
This matches the td with the text, goes up to the parent, then traverses to the input control you want to click.

Facing issues in Identify button in selenium

I am working on 1 project, where i have to locate button, i have used xpath for same, but button id change on every refresh, so i am facing problem in it..
Below is screenshot for same - let me know you can i identify that button so that it will not cause error even if id chages
<button type="button" id="ext-gen11" class=" x-btn-text">Login</button>
Code HTML
<tr>
<td></td>
<td><div id="LoginButton" style="float: left;"><table style="width: auto;" id="ext-comp-1032" class="x-btn x-btn-noicon x-btn-over x-btn-focus" cellspacing="0"><tbody class="x-btn-small x-btn-icon-small-left"><tr><td class="x-btn-tl"><i> </i></td><td class="x-btn-tc"></td><td class="x-btn-tr"><i> </i></td></tr><tr><td class="x-btn-ml"><i> </i></td><td class="x-btn-mc"><em class="" unselectable="on"><button class=" x-btn-text" id="ext-gen12" type="button">Login</button></em></td><td class="x-btn-mr"><i> </i></td></tr><tr><td class="x-btn-bl"><i> </i></td><td class="x-btn-bc"></td><td class="x-btn-br"><i> </i></td></tr></tbody></table></div></td>
</tr>
xPath:
//button[text()='Login']
XPath should do the trick:
Command: clickAndWait
Target: //input[#value='Login']
Edit
Assuming, that there is only one button with value "Login" on it