I am trying to click the CSS below
html body.FormBackground form#LookupForm div#Panel1 table tbody tr td div#GridContainerDiv div table#DataGrid tbody tr.GridSelectedRow td.GridRow
So far I have tried
#FindBy(css = "#DataGrid\\tbody\\tr.GridSelectedRow > td.GridRow")
and
#FindBy(css = "#DataGrid tbody tr.GridSelectedRow > td.GridRow")
But neither of the above attempts seem to work. HTML is below.
<tbody>
<tr ondblclick="$HRnet('DataGrid').dblClick(); " gender_id="f6611f8a-8e80-41e6-a14c-fa8e25be3065" class="GridUnSelectedRow">
<td class="GridRow">Female</td>
</tr>
<tr ondblclick="$HRnet('DataGrid').dblClick(); " gender_id="3ef09fb8-4d5d-43d2-abc0-2506616ef83e" class="GridSelectedRow">
<td class="GridRow">Male</td>
</tr>
<tr nofocus="true">
<td> </td>
</tr>
</tbody>
Based on what you've shared it looks like this should work but it will return multiple rows so you'll need to decide which one you want to click
#FindBy(css = "#DataGrid td.GridRow")
Related
i am trying to send the values to table sorter filter and then select the checkbox of that value .
But unable to get the webElement.
HTML: There are 4 filter box , need to send values to filterbox having index 1.
<tr class="tablesorter-filter-row tablesorter-ignoreRow" role="row">
<td data-column="0">
<td data-column="1">
<input class="tablesorter-filter" placeholder="" data-column="1" data-lastsearchtime="1485173126687" type="search"/>
</td>
<td data-column="2">
<td data-column="3">
<td data-column="4">
</tr>
</thead>
need to send value to given textbox
screenshot
You can try:
//Get a list of all the checkboxes
List<WebElement> listOfElements = webDriver.findElements(By.xpath("//tr[#class='tablesorter-filter-row tablesorter-ignoreRow']/td"));
//click on the text box of index 1.
listOfElements.get(1).click();
I'm having an issue with Selenium in Java.
I have a web page like this:
<html>
<body>
<div id='content'>
<table class='matches'>
<tr id='today_01'>
<td class='team-a'>Real Madrid</td>
<td class='score'>0-0</td>
<td class='team-b'>Barcelona</td>
</tr>
<tr id='today_02'>
<td class='team-a'>PSG</td>
<td class='score'>1-1</td>
<td class='team-b'>Manchester City</td>
</tr>
<tr id='today_03'>
<td class='team-a'>Liverpool</td>
<td class='score'>2-2</td>
<td class='team-b'>Arsenal</td>
</tr>
</table>
<div id='content'>
<body>
<html>
I first get all the rows into a list:
List<WebElement> allRows = driver.findElements(By.xpath("//table[#class='matches']/tbody/tr[contains(#id, 'today')]"));
Next I iterate through all the elements displaying the WebElement (i.e. the row) and on the next line I display the td containing the home team, separated by a line:
for (WebElement row : allRows) {
System.out.println("Outer HTML for row" + row.getAttribute("outerHTML"));
System.out.println("Outer HTML for Home Team cell" + row.findElement(By.xpath("//td[contains(#class,'team-a')]")).getAttribute("outerHTML"));
System.out.println("------------------------------------------------------------");
}
The first println displays all rows, one by one.
The second however displays ONLY 'Real Madrid' for each iteration. I'm losing my mind because I don't understand why. Can someone please help?
The output:
<tr id='today_01'>
<td class='team-a'>Real Madrid</td>
<td class='score'>0-0</td>
<td class='team-b'>Barcelona</td>
</tr>
<td class='team-a'>Real Madrid</td>
------------------------------------------------------------
<tr id='today_02'>
<td class='team-a'>PSG</td>
<td class='score'>1-1</td>
<td class='team-b'>Manchester City</td>
</tr>
<td class='team-a'>Real Madrid</td>
------------------------------------------------------------
<tr id='today_03'>
<td class='team-a'>Liverpool</td>
<td class='score'>2-2</td>
<td class='team-b'>Arsenal</td>
</tr>
<td class='team-a'>Real Madrid</td>
------------------------------------------------------------
You have to use like this
System.out.println("Outer HTML for Home Team cell" + row.findElement(By.xpath("td[contains(#class,'team-a')]")).getAttribute("outerHTML"));
Then it will point to the correct element that we want.
I've tried searching for this one, and tried multiple solutions that I found on here. But so far nothing is working.
The table I'm trying to get data from is being created after entering something into the page. The site then pulls data from what I entered and creates a table. I've had issues with just getting the driver to wait for the table to be visible, it can't find the element.
Here's some html.
<table id="products">
<thead>
<tbody>
<tr class="template subheading-template subheading draggable removeable">
<tr class="template spec-template draggable product removeable odd">
<tr class="components hide modify">
<tr class="draggable product removeable even" data-id="G38180">
<td class="drag"/>
<td>
<td class="cell-gpn">G38180</td>
<td class="cell-rpn">0729151158PROD2</td>
<td class="cell-1 editable">
<td class="cell-2 editable">
<td class="cell-3 editable">
<td class="cell-4 editable">
The cells I want data from have the class "cell-gpn" and "cell-rpn".
Here's some of the code I've tried.
public String getTableData(WebElement table,String rowNumber, String cellNumber){
String text = "";
WebElement row = table.findElement(By.xpath("./tr[" + rowNumber + "]"));
WebElement key = row.findElement(By.xpath("./td[" + cellNumber + "]"));
text = key.getText();
return text;
}
Where table is
#FindBy(xpath = "//table[#id='products']")
public WebElement relatedProductsTableRows;
I am looking for getting the inner most web element in a page, when there are similar nested Webelements in a page.
Consider the example below:
<body>
<table id="level1">
<tr>
<td>
<table id="level2">
<tr>
<td>
<table id="level3">
<tr>
<td>
<p>Test</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table id="level1_table2">
<tr>
<td>
<table id="level2_table2">
<tr>
<td></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
So when I do a search on the page by Driver.findElements by tag "table" and which have some text - "Test",
I will get 5 WebElements in total, namely - "level1", "level3" , "level1_table2" , "level2_table2"
What I want to achieve is to have a list of innermost(nested) elements which satisfy my search criteria .
So the List I should get should only have 2 WebElements namely - "level3" and "level2_table2".
I am looking something probably on the lines of recursion. Can somebody help me out.
You don't need recursion - everything you need is the proper XPath expression:
driver.findElements(By.xpath("table[not(.//table)]"))
I would use this strategy:
Search WebElements containing text Test
For each WebElement search for the first parent which match tag name is table
Here is in Java:
List<WebElement> elementsWithTest = driver.findElements(By.xpath("//*[contains(text(),'Test')]"));
List<WebElement> result = new ArrayList<>();
for(WebElement element : elementsWithTest) {
WebElement parent = element.findElement(By.xpath(".."));
while (! "table".equals(parent.getTagName())) {
parent = parent.findElement(By.xpath(".."));
}
if ("table".equals(parent.getTagName())) {
result.add(parent);
}
}
System.out.println(result);
Hope that helps.
two different Div's inside the Div have an check box, so i want to click the checkbox (i.e inside the "divPatPortfolioStatusCount"), both checkbox xpath are similar
(i.e By.xpath("//input[#accesskey='2']")
Html Code
<div id="divCreatePortfolio" class="wrapper">
<table class="adminlistfilter" width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr data-bind="if: RowCounts>0, attr: {PortfolioId: Id, DescName:Name}" portfolioid="2" descname="Client-Default">
<td style="width: 5%;">
<input type="checkbox" data-bind="attr: { accesskey: Id }" accesskey="2">
</td>
</tr>
</tbody>
</table>
</div>
<div id="divPatPortfolioStatusCount" class="wrapper">
<table class="adminlistfilter" width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr data-bind="if: RowCounts>0, attr: {StatusId: Id, DescName:Name}" statusid="2" descname="Abandoned">
<td style="width: 5%;">
<input type="checkbox" data-bind="attr: { accesskey: Id }" accesskey="2">
</td>
</tr>
</tbody>
</table>
</div>
</div>
my Java code
WebElement statusDiv= driver.findElement(By.id("divPatPortfolioStatusCount"));
WebElement checkBox = statusDiv.findElement(By.xpath("//input[#accesskey='2']"));
checkBox.click();
while executing under the "divCreatePortfolio" checkbox only checked not for "divPatPortfolioStatusCount" let me know the problem with my xpath
You need click on those 2 different check box separately as below right?
//To check Status checkbox
driver.findElement(By.xpath("//div[#id='divCreatePortfolio']//input")).click();
//To check Status count checkbox
driver.findElement(By.xpath("//div[#id='divPatPortfolioStatusCount']//input")).click();
I would suggest you to use css and nth-child() function and control child index from test
body>div:nth-child(1) input
body>div:nth-child(2) input
Changing the number of nth-child(1) from 1 to 2 will find consecutive check boxes
update the xpath in my code
WebElement statusTable = driver.findElement(By
.xpath("//*[#id='divPatPortfolioStatusCount']/table/tbody"));
List<WebElement> rows = statusTable.findElements(By.tagName("tr"));
for (int i = 0; i < rows.size(); i++) {
WebElement checkBoxSts = driver
.findElement(By
.xpath("//*[#id='divPatPortfolioStatusCount']/table/tbody/tr["
+ i + "]"));
String statusAccessKey = checkBoxSts.getAttribute("statusid");
if (statusAccessKey.equals(portfolioId)) {
WebElement checkbox = driver
.findElement(By
.xpath("//*[#id='divPatPortfolioStatusCount']/table/tbody/tr["
+ i + "]/td[1]/input"));
checkbox.click();
break;
}
}
collect the statusid from database with respective of status and pass the statusid in this method with parameter, and proceed
you can do it as :
List<WebElements> lst = driver.findElements(By.xpath("//input[#accesskey='2']"));
for (WebElement web : lst)
if(!web.isSelected())
web.click();
And if you want to select input based on div id u can use:
//div[#id='divPatPortfolioStatusCount']//input