XPath statement not executed in IDE - testing

i faced a problem while replaying a script created for yahoomail page.The XPath statement to enter value in the "To" text field , is not working.Following are the XPath statements i used.
At the first try i used
<tr>
<td>type</td>
<td>to</td>
<td>mgtest#ymail.com</td>
</tr>
Second try was this statement
<tr>
<td>type</td>
<td>//div[#id= 'toid']/textarea[#id= 'to'][#name= 'to']</td>
<td>mgtest#ymail.com</td>
</tr>
Third try was this
<tr>
<td>typeKeysAndWait</td>
<td>//div[# id= 'composebox']/div[#id= 'toid']/textarea[#id= 'to'][#name= 'to']</td>
<td>mgtest#ymail.com</td>
</tr>
The result was like
[error] Element //div[# id= 'composebox']/div[#id= 'toid']/textarea[#id= 'to'][#name= 'to'] not found
similar result was obtained in the previous attempts.
Later when i tried
<tr>
<td>type</td>
<td>css=textarea.txtfield</td>
<td>mgtest#ymail.com</td>
</tr>
mail id was entered into the text field ,and the script worked perfectly.what might be the reason.Any thoughts.?
I am adding the XPath statements
<div id="composepage">
<div id="composebox" class="roundcorner">
<div id="errorContainer"/>
<input type="hidden" name="defFromAddress" value="mgtest#ymail.com"/>
<div class="fields row">
</div>
<div id="toid" class="row">
<label id="compose_to" for="to">
</label>
<textarea id="to" class="txtfield" name="to" autocomplete="off" tabindex="1" style="overflow: hidden; height: 19px;"/>
</div>

You have written invalid xpath query.
It should be
//div[# id='composebox']/div[#id='toid']/textarea[#id='to' and #name='to']

The <textarea> has an id attribute, which should be unique, so your first locator of simply to should work. It's possible that the element is not present or visible when your selenium command executes. I would recommend the following:
waitForVisible | id=to | 60000
type | id=to | mgtest#ymail.com
If your elements have unique ids, and you need to use XPath, you only need to be relative to the closest element with an id attribute.

Related

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']

Need help finding xpath of input field beside label

I have a dom structure like this
<tr class="">
<td class="labelCol requiredInput">
<label for="name_lastacc2" class="">
<span class="requiredMark">*</span>
Last Name</label>
</td>
<td class="dataCol col02">
<div class="requiredInput">
<div class="requiredBlock"></div>
<input id="name_lastacc2" maxlength="80" name="name_lastacc2" size="20" tabindex="3" type="text"></div>
</td>
<td class="labelCol">
<label for="00NG0000008Rybp">Business Ext.</label>
</td>
<td class="dataCol">
<input id="00NG0000008Rybp" maxlength="10" name="00NG0000008Rybp" size="20" tabindex="22" type="text"></td>
</tr>
I am trying to find the input box next to its label.
Eg:
Last Name: ________________
I have tried using xpath queries like
//label[contains(text(),'Last Name']/../following-sibling::*/div/input[#type='text']
but i get an [INVALID XPATH EXPRESSION] error. Where am i going wrong ?
Your path expression is missing the closing bracket of contains().
//label[contains(text(),'Last Name')]/../following-sibling::*/div/input[#type='text']
But that said, I do not think your path expression is correct now. Your expression will match any following sibling of the parent of label[contains(text(),'Last Name')]. What you want it to find is the input element that immediately follows.
The only reason your original expression only finds one input element is that the second one is nested inside one more div. But I do not think you should rely on that.
Instead, try:
//label[contains(.,'Last Name')]/following::input[1]
Then, the result is
<input id="name_lastacc2" maxlength="80" name="name_lastacc2" size="20" tabindex="3" type="text"/>

Selenium checkbox data driven - Checkbox has only target but no value

Im having difficulties parameterizing (data driven) checkboxes using Selenium IDE. When I record selecting a checkbox using Selenium i get the following action:
<tr>
<td>click</td>
<td>id=_ctl0_MainContentPlaceHolder_UseCaseBesturing__ctl1_dgOndersteundeChannels__ctl2_chkbxChannel</td>
<td></td>
In order to parameterize this action and pointing to my test data (XML) file I need a value which I can set as a variable. But in this action there is no value, only a target which is the ID.
Any ideas how to parameterize this action or how to check the checkbox using a value instead of using only the target (ID)?
P.S. Text fields work fine by putting "${Parametername}" in value field in Selenium for an action. The Parametername will then be my column name in my test data file.
Html code of the checkboxes:
<table class="detailgrid" cellspacing="0" border="0" id="_ctl0_MainContentPlaceHolder_UseCaseBesturing__ctl1_dgOndersteundeChannels" style="border-style:None;border-collapse:collapse;">
<tbody><tr>
<td style="width:20px;">
<span disabled="disabled"><input id="_ctl0_MainContentPlaceHolder_UseCaseBesturing__ctl1_dgOndersteundeChannels__ctl2_chkbxChannel" type="checkbox" name="_ctl0:MainContentPlaceHolder:UseCaseBesturing:_ctl1:dgOndersteundeChannels:_ctl2:chkbxChannel" checked="checked" disabled="disabled"></span>
</td><td>
<span id="_ctl0_MainContentPlaceHolder_UseCaseBesturing__ctl1_dgOndersteundeChannels__ctl2_lblChannelNaam">POS</span>
</td>
</tr><tr>
<td style="width:20px;">
<input id="_ctl0_MainContentPlaceHolder_UseCaseBesturing__ctl1_dgOndersteundeChannels__ctl3_chkbxChannel" type="checkbox" name="_ctl0:MainContentPlaceHolder:UseCaseBesturing:_ctl1:dgOndersteundeChannels:_ctl3:chkbxChannel">
</td><td>
<span id="_ctl0_MainContentPlaceHolder_UseCaseBesturing__ctl1_dgOndersteundeChannels__ctl3_lblChannelNaam">eCommerce</span>
</td>
</tr><tr>
<td>
<br>
<span type="checkbox"><input id="_ctl0_MainContentPlaceHolder_UseCaseBesturing__ctl1_dgOndersteundeChannels__ctl4_chkalles1" type="checkbox" name="_ctl0:MainContentPlaceHolder:UseCaseBesturing:_ctl1:dgOndersteundeChannels:_ctl4:chkalles1" onclick="CheckAll('chkbxChannel', this.checked);"></span>
</td><td>
<br>
Alles Aan
</td>
</tr>
</tbody></table>
Still use a click but change how you find the target by using xpath.
It would look something like this:
Target:
xpath=//td/span[text()='POS']
Hope this helps!
After going through the question, I tried using parameter for Target in the test step( as it was not possible to parameterize Action(Command) after various attempts) in Selenium IDE.
To select a checkbox the Xpath should point to the input tag and can be checked using click command.
IMO, as per the HTML, the correct Xpath for checking the checkbox corresponding to eCommerce should be :
//span[text()='eCommerce']/ancestor::td/preceding-sibling::td/input

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"

Facing issues in Identify button in selenium

I am working on 1 project, where i have to locate button, i have used xpath for same, but button id change on every refresh, so i am facing problem in it..
Below is screenshot for same - let me know you can i identify that button so that it will not cause error even if id chages
<button type="button" id="ext-gen11" class=" x-btn-text">Login</button>
Code HTML
<tr>
<td></td>
<td><div id="LoginButton" style="float: left;"><table style="width: auto;" id="ext-comp-1032" class="x-btn x-btn-noicon x-btn-over x-btn-focus" cellspacing="0"><tbody class="x-btn-small x-btn-icon-small-left"><tr><td class="x-btn-tl"><i> </i></td><td class="x-btn-tc"></td><td class="x-btn-tr"><i> </i></td></tr><tr><td class="x-btn-ml"><i> </i></td><td class="x-btn-mc"><em class="" unselectable="on"><button class=" x-btn-text" id="ext-gen12" type="button">Login</button></em></td><td class="x-btn-mr"><i> </i></td></tr><tr><td class="x-btn-bl"><i> </i></td><td class="x-btn-bc"></td><td class="x-btn-br"><i> </i></td></tr></tbody></table></div></td>
</tr>
xPath:
//button[text()='Login']
XPath should do the trick:
Command: clickAndWait
Target: //input[#value='Login']
Edit
Assuming, that there is only one button with value "Login" on it