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']")));
Related
I want to access the table with classname 'table table-hover' that should be under the class=='box-title' that contains the text 'OODR Items for next 20 Days'. Can any one please help me out to get the xpath for this ? I tried with following-sibling but no luck. Thanks in advance.
<?xml version="1.0" encoding="UTF-8"?>
<div id="topTenSellers" class="box box-solid box-primary frontpageWidget">
<div class="box-header">
<i class="fa fa-group" />
<h3 class="box-title">OODR Items for next 20 Days</h3>
<div class="box-tools pull-right">
<button class="btn btn-primary btn-sm" data-widget="collapse">
<i class="fa fa-minus" />
</button>
</div>
</div>
<!-- /.box-header -->
<div class="box-body no-padding">
<table class="table table-hover">
<tbody>
<tr>
<th style="width: 10px">#</th>
<th>Booking</th>
<th>Item Start Date</th>
<th>Site</th>
<th>Supplier</th>
</tr>
<tr>
<td>
<strong>1</strong>
</td>
<td>
(642143)
</td>
<td>21/10/2017 00:00:00</td>
<td>Ski</td>
<td>OODR - Out of Date Range</td>
</tr>
</tbody>
</table>
</div>
<!-- /.box-body -->
</div>
You can try following instead of following-sibling as mentioned h3 and table nodes are not siblings:
//div[#id="topTenSellers"]//h3[#class="box-title" and .="OODR Items for next 20 Days"]/following::table[#class="table table-hover"]
If there is only one element of that class name then either of these will work. One thing to note though, selenium can struggle with spaces in class names depending on the version and browser. If you find that is the case, then use multiple contains to handle the spaces.
//table[contains(#class,'table table-hover')]
//table[#class = 'table table-hover']
If you need that the element as a child of that OODR Items for the next 20 days
//h3[contains(text(),'OODR Items for the next 20 days')]/parent::div/following-sibling::div/table[#class ='table table-hover']
This path uses your anchor point, "OODR Items..", then goes to the parent, then sibling, then to the item with the specified class name. Good luck!
Below is the html markup and I want to extract mobile number 7788996655 using xpath:-
<table class="table hover" id="resultTable">
<tbody>
<tr class="odd">
<td class="left">
<img src="/symfony/web/index.php/pim/viewPhoto/gamerNumber/1/from/gameDir" height="200" width="196">
</td>
<td class="left">
<span style="font-weight:bold;">John Player</span>
<br>
<span style="font-weight:bold;">Email: </span>
john.player#yyeett.com,
<span style="font-weight:bold;">
Mobile: </span>7788996655,
<span style="font-weight:bold;">Skype: </span>
game.player,
<br>
<span style="font-weight:bold;">Designation: </span>
Moderator,
<br>
<span style="font-weight:bold;">Game Name: </span>
Counter Strike
<br>
</td>
</tr>
</tbody>
</table>
I tried below xpath, but it didn't worked:
//td/span[contains(.,'Mobile:')]/following-sibling::text()[1]
Can someone provide solution for this?
Workaround I tried is to get whole text within td and then used pattern matching regex to extract mobile number from it. But, now i want to know whether is it possible using xpath?
You can do it using below XPath
<parent td node xpath>/text()[preceding-sibling::span[1][text() = 'Mobile: ']]
Now for an explanation. /td/text() will select each text which is part of the td node but is not part of any other node. So in this case it ,,7788996655,, game.player, moderator.
Now out of these 4 text we want to filter out one which has a previous sibling, which is a span and has text Mobile:, so we can add [preceding-sibling::span[1][text()='Mobile: ']]
I have a dropdown on a web page for selecting a country which has been rendered using the jQuery Chosen plugin. An extract of the html below,
<div>
<label for="phMainContent_EmployeeAdd1_ddlCountry" id="phMainContent_EmployeeAdd1_lblCountry" class="short required">Country*</label>:
<div id="phMainContent_EmployeeAdd1_ddlCountry_chzn" class="chzn-container undefined chzn-container-single" style="width: 199.44444px;">
<span>Please select ...</span><div><b></b></div>
<div class="chzn-drop" style="left: -9000px; width: 197.222px; top: 28px;">
<div class="chzn-search"><input type="text" style="width: 162px;"></div>
<ul class="chzn-results">
<li id="phMainContent_EmployeeAdd1_ddlCountry_chzn_o_0" class="active-result result-selected">Please select ...</li>
<li id="phMainContent_EmployeeAdd1_ddlCountry_chzn_o_1" class="active-result">United Kingdom</li>
<li id="phMainContent_EmployeeAdd1_ddlCountry_chzn_o_2" class="active-result">Afghanistan</li>
.......
If I use the Selenium IDE to record the actions to select the “United Kingdom” from the list the following script is recorded. Run snippet to see table with the commands in it.
<table border="1">
<tr>
<td>Command</td>
<td>Target</td>
</tr>
<tr>
<td>click</td>
<td>css=a.chzn-single > span</td>
</tr>
<tr>
<td>click</td>
<td>id=phMainContent_EmployeeAdd1_ddlCountry_chzn_o_1</td>
</tr>
</table>
I can run this script repeatably in the IDE and the UK is selected from the dropdown each time. However, if I export the C#/Nunit/Webdriver code below
driver.FindElement(By.CssSelector("a.chzn-single > span")).Click();
driver.FindElement(By.Id("phMainContent_EmployeeAdd1_ddlCountry_chzn_o_1")).Click();
and execute it, it fails on the 1st statement with the Selenium Element Not Visible exception.
Any advice on how to resolve this issue?
you can try xPath and select like //span[contains(.,'Please Select')]
Use explicit wait to make sure the dropdown is visible before the click
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement dropdown = wait.Until(ExpectedConditions.ElementIsVisible(By.CssSelector("a.chzn-single > span")));
dropdown.Click();
driver.FindElement(By.Id("phMainContent_EmployeeAdd1_ddlCountry_chzn_o_1")).Click();
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
<tr>
<td>
<span class="dijitArrowNodeInner" data-dojo-attach-point="arrowNodeInner"/>
</td>
<td>
<div class="dijitTitlePaneTextNode" data-dojo-attach-point="titleNode" style="-moz-user-select: none;">
<div>Scripts</div>
</div>
</td>
</tr>
What will be the xpath for the above expression to get the 'Script'.
If by "the Script" you mean the text content of the inner div element:
/tr/td/div/div
Else, if you mean the div element that has "Scripts" as its content:
//div[. = 'Scripts']
But I doubt this is of much help unless you explain exactly what you need.
From your sample provided, this should work:
//tr/td/div[#class='dijitTitlePaneTextNode']/div[text()]