Unable to Locate the Text in Xpath - selenium

I am writing relational xpath i need this code to fetch "Tax" Location
<td id="td26" style="width: 16%">
<div class="bglabel" style="width: 150px; clear: both">
Tax
<div style="float: right;">
</div>
</td>
Xpath Code which i have written
td[div[text()='Tax ']] - Not Working
td[div[contains(text(),'Tax')]] - Not Working

The accepted answer changes OP's intended logic.
What OP's trying to do is to find div with text "Tax" inside a td, therefore OP's own answer is on the right track, the accepted answer isn't.
//div[contains(text(),'Tax')] locates it anywhere in DOM, which is likely to cause trouble.
What OP wants is (using . to specify current node):
//td[./div[contains(text(),'Tax')]]
Imagine there is another div also contains text "Tax", //div[contains(text(),'Tax')] will find the one OP doesn't want.
<div>Tax table</div>
<table>
<tr>
<td id="td26" style="width: 16%">
<div class="bglabel" style="width: 150px; clear: both">Tax <div style="float: right;"></div></div>
</td>
</tr>
</table>
#Santhosh.S: Hope this makes sense to you.

Related

Make aurelia-ui-virtualization work with tables

I'm struggling to make Aurelia virtual-repeat.for work with table and tr elements. Here is my markup of the modified Users page of aurelia skeleton app:
<table style="width:500px; height: 200px; overflow-y:scroll; display:block">
<tr virtual-repeat.for="user of users" style="width:500px; height: 50px">
<td>
${user.avatar_url}
</td>
</tr>
</table>
When I scroll the table down, the items below aren't rendered and I see just the empty space all over. What am I missing?
The issue was fixed in version 0.4.3, so the described scenario is working now

Selenium IDE to create fb group redactor (or div text input field)

I have some HTML with a (facebook Description text for an event) where I need to enter text, however I cannot find where or how I can add the text, which is a div, span or other. I think this is a redactor (but I'm no expert!)
<th class="_3sts">
<!-- react-text: 77 -->Description
<!-- /react-text -->
</th>
<td class="_480u">
<div class="_mh-">
<div class="_56ji _5yk1">
<div tabindex="-2" class="_5yk2">
<div class="_5rp7">
<div class="_1p1t _1p1u">
<div class="_1p1v">Tell people more about the event</div>
</div>
<div class="_5rpb">
<div style="outline: medium none; white-space: pre-wrap; word-wrap: break-word; background-color: transparent;" title="Tell people more about the event" spellcheck="false" role="combobox" class="_5rpu" aria-owns="js_g" aria-haspopup="false"
aria-expanded="false" aria-autocomplete="list" contenteditable="true">
<div data-contents="true">
<div data-offset-key="9c3am-0-0" data-editor="dvke2" data-block="true" class="">
<div class="_1mf _1mj" data-offset-key="9c3am-0-0"><span data-offset-key="9c3am-0-0"><br data-text="true"></span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</td>
I have tried these in Selenium IDE:
<tr>
<td>type</td>
<td>//div[#title='Tell people more about the event']</td>
<td>testing</td>
</tr>
and
<tr>
<td>type</td>
<td>//th[text()="Description"]/../td/div/div/div/div/div/div/div/div/div/span/</td>
<td>test</td>
</tr>
and (to apply a redactor solution)
<tr>
<td>runScript</td>
<td>$(._5rpu).html('text');</td>
<td></td>
</tr>
But while I can easily identify the area (one of the many divs) that seem to reflect the space where the text should go I can't manipulate it. Any help appreciated! ;-)
That field is not a trivial case.
First of all it's not an input. That's why "type" command will not work even if you will find element properly.
Secondly the div is in dynamic change when you are entering text that's why you cant use sendKeys for long text because this command is sending symbols one by one to the element that was located once. So after the first successful symbol sending, DOM of the element will be changed and it will become impossible to finish sending other keys.
But you can send one symbol using sendKeys like that:
sendKeys | //div[#class='_5rpu'] | Y
Finally because of unknown reason you can't send symbols with series of sendKeys commands like:
sendKeys | //div[#class='_5rpu'] | Y
sendKeys | //div[#class='_5rpu'] | O
That will throw an exception
[error] Unexpected Exception: Error: Cannot set the selection end.
The only way I've found is to use an ancient and deprecated typeKeys. After typeKeys command you also need a click a whole div which is containing field because orthodox typeKeys is working incorrect with that strange field too.
Also you need to be fully sure that all the animations was showed before you will start. That's why I recommend a small pause before you will try to type to the field.
So here is the final and working code:
pause | 2
typeKeys | //div[#class='_5rpu'] | myDescription
click | //div[#class='_56ji _5yk1']

What will be the xpath for below expression

<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()]

How to search by first td text and clicking in seconds td href by JUnit, Webdriver?

<div class="row">
<div class="row">
<table>
<tbody>
<tr>
<td class="list-text">
<div style="background-color: transparent;">Testing this function</div>
</td>
<td class="list-buttons" rowspan="2">
Config
<a class="edit-button" href="javascript:;">Edit</a>
<a class="save-button" href="javascript:;" style="display:none;">Save</a>
Delete
</td>
</tr>
<tr>
</tbody>
</table>
</div>
I need to find the element which contains the text "Testing this function" and click to link "Config".
Can't find a way to do it.
Edited: Found a way to do it:
By.xpath("//div[#class='row']/table/tbody/tr[td/div[contains(.,'Testing')]]/td[2]/a[contains(.,'Config')]")
But maybe someone has a better solution for this?
If you have to use text, my preference would be;
By.xpath("//div[contains(text(),'Testing')]]//a[contains(text(),'Config')]") .
I prefer using "text()" to "." just for readability. Apologies if "." is actually a better approach which I wasn't aware of.
Also unless you have a specific reason, I would avoid using tightly coupled xpath. E.g. I have not used " td[2]", instead I have said the"a" can be anywhere within in the "div"

Using Campaign Monitor to send emails, is there any way to get rid of the 5px white space above text in a vertical-align table?

Sending out mass emails, pretty much the whole thing is inside tables.
CSS affecting the table:
.title {
vertical-align: top;
}
HTML:
<table width="580" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="title" align="left" width="440" valign="top">
<h2><singleline label="Title">Enter your title</singleline></h2>
<p><multiline label="Description">Description</multiline></p>
</td>
<td align="left" valign="top" width="20"><img src="/images/00.gif" height="1" width="20" border="0"></td>
<td align="left" valign="top" width="120"><img src="/images/001.jpg" editable="true" label="Image" width="120" border="0"></td>
</tr>
<tr>
<td colspan="3" align="left" valign="top" width="580"><img src="/images/00.gif" height="20" width="1" border="0"></td>
</tr>
</table>
I need the text inside the tag to be flush with the top of the table. Currently the /images/001/jpg is flush, but the text is 5 pixels below the edge of the table.
I'm using vertical-align: top in the CSS, have tried border-spacing: none, border-collapse: collapse, and border: none. None of them solved the problem.
Using margin-top: -5px; on the tag solved the problem in standard browser testing, but wasn't supported by some email clients.
this is Ros from Campaign Monitor. What isn't entirely obvious is that the <singleline> and <multiline> tags convert into <p>your content</p>
...when imported into the Campaign Monitor editor. It's these <p> tags that are creating this extra padding - here's an example.
The easiest way to avoid this is to add p { margin: 0; padding: 0; } to your CSS styles.
Hopefully this fixes this issue for you. Note that we have a forum for answering questions like this, so feel free to post your template code there in the future.
Many thanks to everyone who contributed here!
Ros' suggestion suffices most of the time, but Gmail removes your header styles which leaves the inserted p tags with gmail's default margin top and bottom.
An alternative to get around this is by adding a div tag within your multiline tag. This will successfully prevent Campaign Monitor from wrapping your content with a p tag.
Here is a structure example:
<multiline>
<div>
Your Content Goes Here.
</div>
</multiline>
Put
valign="top"
on your TD for the text. If the email client doesn't recognize CSS it should recognize the standard HTML attribute.
Also, if that doesn't fix it, can you edit your Q and add the definition for "title" CSS definition that you are using on that .
I'm assuming your referring to the text inside the H2 tag.
Create a class for the <h2>
.noPad {
padding-top: 0px;
}
Or don't use the H2 and just use a span or div element.
It could just be the line-height of the text as opposed to margin/padding - check that as well