Click on a table link in selenium webdriver - selenium

Please find the sample code below
<tbody>
<tr>
<td class="menubox">
<table id="menubar" border="0">
<tbody>
<tr id="mytr">
<td class="level1" id="panel" onclick="popupwin onmouseover="this.classname onclick="popupwin"> menu1</td>
<td class="level1" id="panel" onclick="popupwin onmouseover="this.classname onclick="popupwin"> menu2</td>
<td class="level1" id="panel" onclick="popupwin onmouseover="this.classname onclick="popupwin"> menu3</td>
I am tring to access the menu3 column which is a link by xpath
//table[#id='menubar']/tbody/tr/td[3] but throwing an error no such element
found. could any one suggest what is wrong in the xpath ?

can you please try this:-
//tr[#id='mytr']//td[3]

Not sure why your Xpath wasn't working, your table structure and xpath is matching together.
However please try following xpath which might work. and if the website your testing is public. please provide the link.
//tr[#id='mytr']/td[contains(text(),'menu3')]

Related

How to create conditional xpath in selenium?

My HTML code looks like:
Table 1: And Table 2
<table id="ContentPlaceHolder_Body0">
<tbody>
<tr align="Center">
<td style="width:250px;">Some Name</td>
</tr>
</tbody>
</table>
<table id="ContentPlaceHolder_Body1">
<tbody>
<tr align="Center">
<td style="width:250px;">Some Name</td>
</tr>
</tbody>
</table>
When I use //*[contains(text(),'Some Name')] this xpath selects 2 values while I need to select only one value by Text.
I need to use that xpath with Text.
I'm trying to create xpath to get the "Some Name" from Table 2, element locator by using Text.
So I created this Xpath:
//table[#id='ContentPlaceHolder_Body1']//tr//td[#text()='Some Name']
This xpath is not working, need help to create correct xpath.
Given your HTML, this XPath works for me
//table[#id='ContentPlaceHolder_Body1']//td[text()='Some Name']
I think the issue with your XPath is that you were using #text() when it should be text().
//table[#id='ContentPlaceHolder_Body1']//tr//td[#text()='Some Name']
^ remove the #
You need to just remove the #
//table[#id='ContentPlaceHolder_Body1']//tr//td[text()='Some Name']

Robot Framework - Unable to find filter xpath in Kendo grid and add text

I am attempting to create a Robot Framework Selenium test where I input text into a Kendo grid filter and then check the results. The grid is here:
The filter code is here:
<thead class="k-grid-header" xpath="1">
<tr>...</tr>
<tr>
<td class="rowFilterContainer"></td>
<td class="rowFilterContainer"></td>
<td class="rowFilterContainer" data-field="UserId"></td>
<td class="rowFilterContainer" data-field="CandidateId">
<input class="rowFilter" data-field="CanddateId" data-type="string" type="text" data-
operator="startswith">
</td>
I am attempting to locate and then enter text in the CandidateId field using Selenium with an xpath of "//div[#id='Tab_0']//td[4]//input[1]" but when I run the test if complains that it cannot find it.
Any help on how to find this field (with a better xpath) and to add the text would be greatly appreciated. I have tried using CSS as well.
Try this xpath:
//td[#data-field='CandidateId']/input
Try this:
(.//thead[#class='k-grid-header']/tr)[2]/td[4]/input[#class='rowFilter']

How to get xpath from "Page Should Contain" in a web page using RobotFramework and Selenium

I'm writing test cases for a webpage that has a table as the main focus of the page. I'm checking that the page contains a new entry via the Page Should Contain fucntion, I then want to find the xpath for this element. I am doing this because each entry is added to the end of the table so I cannot set a static xpath for it because I don't know how many entries will be added between each run of this particular test.
Thanks in advance.
<table class="fw-table">
<thead>
<tr class="affix-header">
<th class="columnwidth-description">Email</th>
<th>Account</th>
<th>Signed up</th>
<th>Number of invalid attempts</th>
</tr>
</thead>
<tbody>
<tr>
<td>devtest</td>
<td>Account</td>
<td>true</td>
<td>0</td>
</tr>
<tr>
<td>test#testing.com</td>
<td>Account</td>
<td>true</td>
<td>1</td>
</tr>
search for: xpath=//body/div[2]/div/div[2]/div[2]/div/div/table/tbody/tr[1]/td[1]
If you need to verify that last table row contains certain text you can use the Page Should Contain Element keyword and provide an xpath locator which will find the last table row containing your text:
Page Should Contain Element xpath=//table[#class="fw-table"]//tr[last()]//td[contains(text(),'bottomline')]

Clicking other cell's child element in Selenium WebDriver Java

What is the code to be used to click the "a" element by looking first for the "td" that contains certain texts?
<table>
<tbody>
<tr>
<td><a class="link">link</a></td>
<td>1st</td>
</tr>
<tr>
<td><a class="link">link</a></td>
<td>2nd</td>
</tr>
</tbody>
</table>
I used this code but it doesn't work.
driver.findElement(By.xpath("//td[contains(text(), '1st')]/following-sibling::a[#class='link']")).click();
Try this xPath //td[contains(text(), '1st')]/../td/a[#class='link'].
Your mistake comes from the axis "following-sibling". The tag a is not a sibling of the td tag. I use .. to go up, then select td again and then a.
I tested the xPath using http://www.xpathtester.com/xpath. It works. Beware that every browser comes with their own xPath implementation, therefore it could behave a bit differently.
However, as there is nothing exotic in the xPath expression, I don't expect any problem.

XPath Text Search/Sibling Selection

This question might be a little specific but the test program im writing uses XPath to find the data i need in HTML. This piece of HTML(found here) is what im trying to parse.
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="textSm" align="right">1. </td> <!-- Location of the number is here -->
<td align="left" nowrap>
P Sandoval <!-- Player location is here of the number is here -->
</td>
</tr>
</table>
My goal is to find the name of the person by using the number that corresponds to him to find him. This requires me to find a node by the specific text contained in "td class="textSm" align="right">1. </td>" and then find the sibling of that node "<td align="left" nowrap>" then find the child of that sibling "P Sandoval" to get the desired result. I was wondering what kind of query I could use to find this. Any help is very much appreciated.
Use:
table/tr/td[starts-with(., '1.')]/following-sibling::td/a
This assumes that the context (current node) against which the XPath expression above is evaluated, is the parent of table.
//tr[td = "1"]/td[2]/a
For all TRs which have a TD equal to '1', give from the second child TD the A element.