I have a dropdown element that i'd like to select, but for some reason xPath is not resolved , i don't understand why.
This is the html :
<td id="Vertical_v8_57849360_MainLayoutEdit_xaf_l195_xaf_l204_xaf_dviDate_Edit_B-1" class="dxeButton dxeButtonEditButton_XafTheme" style="-webkit-user-select:none;"><img id="Vertical_v8_57849360_MainLayoutEdit_xaf_l195_xaf_l204_xaf_dviDate_Edit_B-1Img" class="dxEditors_edtDropDown_XafTheme" src="/DXR.axd?r=1_88-f49pk" alt="v"></td>
and this is my selector :
$x("td[contains(#id,'xaf_l195_xaf_l204_xaf_dviDate_Edit_B-1')]")
Your selector is fine, but the html is malformed: the <img>child node of <td> doesn't have a closing tag, it should be
<img id="Vertical_v8_57849360_MainLayoutEdit_xaf_l195_xaf_l204_xaf_dviDate_Edit_B-1Img" class="dxEditors_edtDropDown_XafTheme" src="/DXR.axd?r=1_88-f49pk" alt="v"/>
If that is fixed, the xpath should work.
Related
I have the following html code:
<tr id="id that I want to obtain via title">
<td class="icon">
<span class="greenArrowIcon pid-1-arrowSmall"></span>
</td>
<td class="bold left noWrap elp">
<a href="..." title="title that I have obtained">
TITLE
</a>
<MORE CODE>
</td>
</tr>
and I know that the tag title title="title that I have obtained" are always the same, but the id id="id that I want to obtain viva title" could change, is strange that changes, but could.
So, my question is: How can I find the id via the title ? I think the problem is that the title tag is inside (an inferior jerarchy) from the id that I want to solve it.
I am using Selenium, and this is the code to solve the title and get the web element:
driver.find_element_by_css_selector("[title^='title that I have obtained']")
Is it possible do this?
To find the desired id attribute value you can use the following XPath locator:
tr = driver.find_element_by_xpath("//tr[.//a[#title='title that I have obtained']]")
id = tr.get_attribute("id")
Already #Prophet answered in a good way but I want to show you other ways to find the same element.
Using parent function:
//a[#title='title that I have obtained']//parent::td//..
//a[#title='title that I have obtained']//..//parent::tr
Using ancestor function:
//a[#title='title that I have obtained']//ancestor::tr
I have something like this:
<td th:text="${e.name}">My Event</td>
I need to add a hyperlink to e.name but I can't figure out how, and I think my google skills may be lacking as well since I can't find anything on how to do it.
Thanks for any help.
Just as in a normal HTML document you'll need to wrap an anchor element around what you want to link. For instance like this
<a th:href="#{http://www.thymeleaf/documentation.html}"><td th:text="${e.name}">My Event</td></a>
Other variants can be found by reading the Thymeleaf Standard URL Syntax
It should look like this:
<td>My Event</td>
You can use th: attributes on any html tag.
Here's an example declaring everything in the href and using an expression to modify the wrapped text:
<td><a th:href="#{${obj.website}}" th:text="${#strings.abbreviate(obj.website,50)}" /></td>
One declares the text and the href inside of the anchor tag.
I select all <a> elements inside all <td> elements
<td class="thread">
<i class="ter green"></i>
Something about...
<p class="info">Author</p>
</td>
I use the following:
driver.findElements(By.cssSelector("td.thread a"));
However, I'm getting much more elements than there should be. I guess that I must select only first a inside td class="thread". How can I do that?
When you use the CSS Selector td.thread a, that reads any descendant a under td.thread. What you more likely want is td.thread > a which reads a child a of td.thread. It's still possible there are more than one a but you will likely get a lot fewer depending on the overall HTML.
CSS Selector reference
thread = driver.find_element_by_class_name('thread')
correct_link = thread.find_element_by_tag_name('a').get_attribute('href')
print(correct_link)
>>> "/forum/threads/12/"
i made this page yesterday and href links doesn't work...
HTML and CSS source here: https://titanpad.com/jmAHmU3GyI
I may not understand exactly what you're asking, but the href attribute belongs inside an anchor tag, like so:
<td>Link</td>
Specification: http://www.w3schools.com/tags/att_a_href.asp
Demo: http://jsfiddle.net/0mtto06n/
You are using the href attribute on <li> elements which is unfortunatelly not going to work. To create links use Link text
Read more here:
about a tag
Using xpath,I need to select text "level38a" using dynamic id "select" link. In HTML code i see containing 2 <td> with text "level38a" and "select".
PS : In my application i have more than 30 "select" link for different text. So using the id="lnk_LEVEL_2449" is not efficient.
I'm using the below code to select the text, but it's not clicking the select button.
driver.findElement(By.xpath("//tr[td//a[#value='Select']]/td/a[contains(text(),'level38a')]"));`
HTML snippet
<tr>
<td>
<img class="imHeader" alt="" src="include/img/context/level_dash.gif">
<img class="imHeader" alt="" src="include/img/context/icon_telco_level.gif">
level38a
</td>
<td> </td>
<td>
<a id="lnk_LEVEL_2449" href="jfn?isLevel=true&level=L4%3A2449&mfunc=614&cfunc=615&oid=L4%3A2191&ctx=L&jfnRC=9">Select</a>
</td>
</tr>
This method
driver.findElement(By.xpath("//tr[td//a[#value='Select']]/td/a[contains(text(),'level38a')]")); only finds the element, doesn't click it.
You have to add click() action. Like this:
driver.findElement(By.xpath("//tr[td//a[#value='Select']]/td/a[contains(text(),'level38a')]")).click();
Edit:
I haven't looked at your xpath. It is wrong.
Please try these:
"//tr[td//a[contains(text(), 'Select')]]/td[contains(text(),'level38a')]"
or just:
"//td[contains(text(), 'level38a')]"
Used the below xpath to select dynamic ID's and it worked fine. First it locate the text "level38a" in the page and click on "Select" link.
driver.findElement(By.xpath("//tr[td[contains(text(),'level38a')]]/td//a[contains(text(), 'Select')]")).click();