(1) html:
<table class="title_button" onclick="onSave();" onmouseout="this.className='title_button'; save_moveout();" onmouseover="this.className='title_button_hi'; save_movein();" title="Copy Running-config to Startup-config">
<tbody>
<tr>
<td>
<img id="title_btn_save" src="https://192.168.100.116/image/title_btn_alert.gif">
</td>
<td id="title_save">Save</td>
</tr>
</tbody>
</table>
(2) Webdriver Java:
tried these two ways both can't work.
driver.findElement(By.id("title_save")).click();
driver.findElement(By.xpath("/html/body/div/table/tbody/tr/td/table/tbody/tr/td[8]/table/tbody/tr/td/div/table/tbody/tr/td[2][#id='title_save'")).click();
(3) Exception:
webdriver element is not currently interactable and may not be manipulated.
You are trying to click the td element, but the actual "clickable" element here is the table:
driver.findElement(By.className("title_button")).click();
It looks like element you try to click in disabled and click operation cannot be performed to this element.
Try to perform click operation on another element e.g. on :
driver.findElement(By.css(".title_button tr")).click();
Related
<tr class="odd" role="row">
<td>PRODTUT020</td>
<td>Product for tours</td>
<td>
<td>
<ul class="icons-list">
<c:if test="true">
<li class="text-info-600">
<a href="edit-se-product_mst-90" title="View">
<i class="icon-eye"/>
</a>
</li>
</c:if>
</ul>
</td>
</tr>
Above is the html body. Want to click on the icon-eye element. How do we identify this element using selenium locators?
This XPath,
//tr[td="PRODTUT020"]//i[#class="icon-eye"]
will select i elements with #class attribute value of icon-eye beneath the tr element whose td child has a string value of PRODTUT020.
Depending upon what's more invariant across your general cases, you might change PRODTUT020 to Product for tours -- both work for the case you show.
It avoids having to name the namespaced element by skipping past it via //.
If you want to fetch i inside c:if element you can use below expression
'//*[name()="c:if" and #test="true"]//i'
I'm newby in selenium automation.
I have one scenario where I have to click on a button based on some title. but the button element looking same for all all rows.
This is the image:
this is html for the same-
<tr class="odd gradeX">
<td class="hide"></td>
<td>My sample Test</td>
<td> Priyank pareek </td>
<td style="width:50px;text-align:center;">01/11/2017</td>
<td style="width:50px;text-align:center;"> Approved </td>
<td style="width:50px;text-align:center;">
<td style="width:100px;">
<a class="btn btnReject red btn-sm btn-outline sbold uppercase" href="javascript:;" onclick="updateTest(this)" data-status="0" data-gui="6438C99F-E166-49DA-8B89-DD0E2EF33A62" title="Reject">
</td>
</tr>
How can i click on the reject button ? please help me
You can use below XPath:
WebElement element = driver.findElement(By.xpath("//a[#title='Reject']"));
or CSS selector
WebElement element = driver.findElement(By.cssSelector("a[title='Reject']"));
If these selectors still matches multiple elements, try:
WebElement element = driver.findElement(By.xpath("//tr[td[text()='My sample Test']]//a[#title='Reject']"));
Try to locate using following xpath -
//td[text()='My sample Test']/following-sibling::td/a[#title='Reject']
Explanation :-
Find the td tag which having text as 'My sample Test'
following-sibling used to navigate the sibling which have reject button
You can search using class name btnReject. In Python, I usually use driver.getElementByClassName("btnReject").click(). You can change them into Java to use.
I'm trying to extract values from td tag, but it doesn't work, one of td contains value which is called "Technology", and I want to get td value which is after him, for example td is 'Technology' and td which is after that: 'Windows Server' <- how can I get this value? here is a code:
</td>
</tr>
</tbody>
</table>
</dd>
<dt>
Informacje o kursie</dt><dd id="course-info"><table><tbody>
<tr>
<td>Odbiorcy:</td>
<td style="text-transform: capitalize;">IT Professionals</td>
</tr>
<tr>
<td>Technologia:</td><td>Windows Server</td>
</tr>
<tr>
<td>Poziom:</td><td>300</td>
</tr>
<tr>
<td>Bieżąca wersja:</td><td>B</td>
</tr>
when I'm doing something like that:
for (Element element : doc.select("#course-info").first().children()){
if(element.text().contains("Tech")){
System.out.println(element.nextElementSibling().html());
}
}
Then NPE appears (element), but when I delete this loop, whole method works fine.
The specific CSS selector for "Windows Server" is #course-info > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(2).
If you want to know which selector to use, open your browser's developers tools (F12), and inspect the DOM. Select the desired element and get the selector.
I believe that you have more rows in your table, so you'll have to loop thru. the table, by changing one (or more) of the number constants in the above selector.
I have the following table:
<table>
<tbody>
<tr>
<td>
</td>
<td>
User1
</td>
</tr>
<tr>
<td>
</td>
<td>
User2
</td>
</tr>
</tbody>
</table>
I want to find the a-tag of the tr, where the data User2 is in the same row. I know that I can find an a-tag with partial link like findElement(By.partialLinkText("/ResetPassword/")); (the number 2 can change, so I can´t use it as seperator). But I need to seperate it by User. Is there a solution like tr.td.text("User2") > findElement(By.partialLinkText("/ResetPassword/"));?
This XPath should do the trick for you. .//tr[td[normalize-space(text())='User2']]//a Just keep changing "User2" part with the desired user value.
Hi I was wondering if you could use the .getValue() statement with /#a at the end of the xpath to locate the attribute "a".
Main thing to do is find a bulletproof xpath to locate the User2 row once you have done that finding the value of "a" should be easy enough.
I hope this helps
U can try something like this(not sure though)-
List<WebElement> list=table.findElements(By.tagName("tr"));
List<WebElement> tdvalues=null;
for(WebElement web:list){
tdvalues=web.findElements(By.tagName("td"));
if(tdvalues.contains("User2")){
System.out.println(tdvalues.get(0).getText());//0th position contains the link
}
tdvalues.clear();
}
<tbody>
<tr class="odd">
<td>
<input id="nodeAccountOid" type="radio" onclick="setNodeAccountIdToCredentialCheck('E9E2930C4493B569E040A8C0158E4ABD');" style="width:100%;border:0px">
</td>
<td>E9E2930C4493B569E040A8C0158E4ABD</td>
<td>monacho1</td>
<td>urn:dece:org:org:dece:dece:cs</td>
</tr>
<tr class="even">
<td>
<input id="nodeAccountOid" type="radio" onclick="setNodeAccountIdToCredentialCheck('E9E2930C4494B569E040A8C0158E4ABD');" style="width:100%;border:0px">
</td>
<td>E9E2930C4494B569E040A8C0158E4ABD</td>
<td>monacho1</td>
<td>urn:dece:org:org:dece:coord:cs</td>
</tr>
<tr class="odd">
<td>
<input id="nodeAccountOid" type="radio" onclick="setNodeAccountIdToCredentialCheck('E9E2930C4495B569E040A8C0158E4ABD');" style="width:100%;border:0px">
</td>
<td>E9E2930C4495B569E040A8C0158E4ABD</td>
<td>monacho1</td>
<td>urn:dece:org:org:dece:300</td>
</tr>
<tr class="even">
<td>
<input id="nodeAccountOid" type="radio" onclick="setNodeAccountIdToCredentialCheck('E9E2930C4495B569E040A8C0158E4ABD');" style="width:100%;border:0px">
</td>
<td>E9E2930C4495B569E040A8C0158E4ABD</td>
<td>monacho1</td>
<td>urn:dece:org:org:dece:10</td>
</tr>
</tbody>
</table>
i want to select the radio button corresponding to urn:dece:org:org:dece:10 which is fourth row in the html provided. the row may change sometimes based on some inputs in AUT. please provide me the way to select it.
thanks in advance
Since the text never changes, you can use that as a starting point within the DOM, and use XPath to navigate through to the input you need:
//td[.='urn:dece:org:org:dece:10']/parent::tr/descendant::input[#id='nodeAccountOid' and #type='radio']
Get the td that has it's text equal to urn:dece:org:org:dece:10
Get that td's parent tr
From that parent tr, get the input that has an id equal to nodeAccountOid and has a type of radio.
Therefore it doesn't matter where exactly the elements are, as long as the XPath locator can navigate up to the parent and back down again to the input you need.
The problem you are facing is to locate a certain element in the web page that may occur in different positions.
If there is another element which can be identified easily by its content, id or name and there is a static relation between this element and the one you would like to locate, then you could use xpath. There are also some examples for this in the selenium documentation as far as I know.