Selenium Test Case/Suite - html

My Selenium Test Case and Test Suite is not working properly, for some reason when I play each test case separately, it works, however, when I play the whole thing together, it says: 'Element ... not found' and also, if I add both test cases to a new test case and play this new test case, it doesn't work. I am assuming my first test case is fine as that always works, but it gets the element not found error at this point, and I have tried other ways as well:
<tr>
<td>click</td>
<td>//div[#class='btn_sel_text' and contains(., 'Volume Entry')]</td>
<td></td>
</tr>
I also tried replacing the '//div' with:
css=.btn_sel_text:contains('Volume Entry')
however that didn't work either. Can anyone please explain why it doesn't work when I run the whole thing together, however, if I simply run the //div or the 'css' on it's own it does work.

put a pause before click.
command:pause
Target:3000
Try it,Thank you.

Find Xpath of that element using firepath. with Xpath of element you can click on it. do this & let me know your problem is solved or not
<tr>
<td>pause</td>
<td></td>
<td>1500</td>
</tr>
<tr>
<td>click</td>
<td>Xpath of the element </td>
<td></td>
</tr>

In trying to debug this problem for myself, I found that if I had two test cases that worked individually and then when I ran them together in a test suite a link/button could not be found in the second test case, the solution was actually to modify the FIRST test case.
If you have more than two test cases, try changing the order around so that there is some other test case immediately following the original first test case. When I tried that, my error moved from the original second test case to the new second test case.
I don't know exactly why, but it is like Selenium is unable to catch up with the effects of the first test on the browser or something. If add, however, a 'pause 5000' followed by a ClickAndWait (to an inocuous link that keeps me on the same page, perhaps) to the end of the
first test case, then when the first and second test case are run together in the test suite, the second test case now works.

Related

Using groovy script on Katalon to click on row of grid

With groovy script on Katalon, I want to click on first row of grid but it is not working and it shows error (error.png with Option1 mentioned below) in console.
I have tried by targeting different element's xpath of row but it seems click() event is not being recognized. Also, added wait and waitForPresentElement but did not work.
Following are three options I tried so far but none of them worked.
Groovy on Katalon:
Option 1:
WebUiCommonHelper.findWebElement(By.xpath("//div[#class='dgrid-row dgrid-row-even ui-state-default']/table/tr/td/span[#class='dijitIconFlag dijitFixedMatterIcon']")).click()
Option 2:
WebUiCommonHelper.findWebElement(By.xpath("//div[#class='dgrid-row dgrid-row-even ui-state-default']/table/tr/td[contains(#class,'dgrid-cell dgrid-cell-padding dgrid-column-0-')]").click()
Option3:
WebUI.click(findTestObject('Object Repository/Page_Law Practice Management Software CosmoLex/td_Client Funds-Trust_dgrid-cell dgrid-cell_865aa6'))
Source code:
Source code is in xPath.jpg.
Expected:
The row should be selected/clicked.
//table[#class="dgrid-row-table"]//tr//td
Use this as xpath,
and click by this manner.
Hope it will help you.
List<WebElement> objects = WebUiCommonHelper.findWebElements(findTestObject('***put xpath url here***'), 30)
WebUI.delay(1)
objects.get(0).click()

How to make this code work in a Wordpress

Here is the code:
a:4:{i:2;a:3:{s:5:"title";s:78:"[:lt]naujas numeris[:en]
latest publication";s:4:"text";s:212:"<a
href="http://www.example.com/p/post-post/" target="_blank"><img
src="http://www.example.com/wp-content/uploads/2015/03/200x300.jpg"
height="254" width="165"></a>";s:6:"filter";b:0;}i:3;a:3:{s:5:"title";
s:78:"[:lt]Naujausias numeris[:en]latest
publication";s:4:"text";s:212:"<a href="http://www.example/post/"
target="_blank"><img src="http://www.example.jpg" height="254" width="165"></a>";s:6:"filter";
b:0;}i:4;a:3:{s:5:"title";s:68:"[:lt]ATSARGIAI:
[:en]CAREFUL:";s:4:"text";s:809:"<div id="widgettext">
/div>
<table>
TABLE
</table>
<div id="tarpelis"></div>
<div id="rudalinija"></div>
<div id="tarpelis"></div>
<div id="tarpelis"></div>";s:6:"filter";b:0;}s:12:"_multiwidget";i:1;}
This piece of code is a record in a website wp_options DB table (optopn_name: widget_text). I had to change one element of the code (TABLE), but right after that some problems occured (like previous table dissapeared). I fixed back the code, but looks like whenever i change name of the person in this table it dissapears on the website.
<tr>
<td><!--:lt-->Name Surname<!--:--><!--:ru-->Name Surname<!--:--></td>
</tr>
Do you have an idea why could this happen?
Also that code a:4:{i:2... is a bit troubling me, can you explain me what that does? It may be the case.
This is a compressed, minimized version of the original javascript or markup or other code that had the names of functions and variables changed to make things as small as possible. You can spend time looking through it to find it all but it can take a while.
Somehow missed that, but solution was quite easy. Turns out the only way to change it was to go to appearance(widgets) where i found this table. Eventhrough it is still strange that changing data in the database (where is stored that post with table) resulting to invalid post. Still thank you for your suggestions :)

"element does not exist in cache" error upon radio button select using mechanize::phantomjs

I'm trying to automate a webpage that includes a lot of javascript functions in Perl. So far I've been successful by using the headless mechanize::phantomjs toolkit, but I can't get past this, probably, trivial error. I see a page with a menu of radio buttons and when I try to select any one of those using
$mech->set_fields('booking_choice' => "$i");
where $i is my iterator and 'booking_choice' is the name of the button, I get the error listed below. This is how it looks on the page:
<tr bgcolor="white">
<td>
<input type="radio" name="booking_choice" value="1">
</td>
<td class="tableTxt">
Friday, January 16, 2015</td>
<td class="tableTxt">
08:45 a.m.</td>
<td class="tableTxt">
45 minutes</td>
</tr>
There are two other radio buttons with values 0 and 2, and that's what the iterator is for. However, within any one iteration upon selection of the button I get the following error:
Error while executing command: An element command failed because the referenced element is no longer attached to the DOM.: {"errorMessage":"Element does not exist in cache","request".....
I can locate the button on the page fine by using xpath and it always returns success:
if ($mech->xpath('//*[#name="booking_choice"]', one => 1)) {
say "Success";
}
What I don't understand is:
Why the element is no longer accessible even when I can see it listed on the html source page.
How can I keep the Element intact so that it is available for selection.
I'm very new to webscraping, web automation and I found some similar question to mine on this forum but they are either written for ruby or use some other webdriver than phantomjs. I don't know how to implement any of the given solutions using mechanize::phantomjs. I'll appreciate any help I can get. Thanks!
I've placed the source HTML file here: http://www.datafilehost.com/d/948c5371
mechanize requires you to select the form before you can set the form fields. This can be done with a variety of functions such as
$mech->form_name( $name [, %options] )
$mech->form_id( $id [, %options] )
$mech->form_number( $number [, %options] )
$mech->form_with_fields( [$options], #fields )
Taken from here.
If this doesn't work, you can always run some custom code in the page context to change the fields. For radio boxes this would look like this:
$mech->eval(<<'JS', $i);
document.querySelectorAll("[name='formName'] [name='radioButtonName']")[arguments[0]].checked = true;
JS
Although, this only changes the property of the radio button and in most cases this is enough. But sometimes there are event handlers on the DOM elements which will not be triggered in this case.
An alternative would be to actually use $mech->click( $name [,$x ,$y] ) to click on the radio button and trigger all necessary events.

Selenium click doesn't work but mouse does

Can anyone explain why/how in Selenium IDE, for an item I want to click on, the click doesn't work, however using mouseOver, mouseDown, mouseUp and mouseOut on the same Target does work. I have even tried to use multiple of those above, e.g.:
waitForElementPresent
mouseDown
mouseOver
mouseDown
click
mouseOut
This managed to work for me on something else, when using click didn't work. I also don't seem to be getting any errors and don't know what to do. Any help is appreciated.
UPDATE:
I clicked on the Find button in Selenium IDE and it highlighted the element, with all 6 of those Commands above, but it never actually clicks it when I run any of the commands or the case.
there are all sorts of implementations for click out there,
some use Javascript that listen to the mouse down event, some use the mouse up or click or mouse over the div or td they implemented as a clickable element and then the JS start working and you get the click action expected,
therefor there is no one correct event you should launch, rather test them all or execute them all,
i use the following commands and it works for most elements that doesn't work with a simple 'click' command:
<tr>
<td>focus</td>
<td>//div[#class='dhtmlx_wins_btns_button dhtmlx_button_close_over_pressed']</td>
<td></td>
</tr>
<tr>
<td>mouseOver</td>
<td>//div[#class='dhtmlx_wins_btns_button dhtmlx_button_close_over_pressed']</td>
<td></td>
</tr>
<tr>
<td>mouseMoveAt</td>
<td>//div[#class='dhtmlx_wins_btns_button dhtmlx_button_close_over_pressed']</td>
<td></td>
</tr>
<tr>
<td>mouseDown</td>
<td>//div[#class='dhtmlx_wins_btns_button dhtmlx_button_close_over_pressed']</td>
<td></td>
</tr>
<tr>
<td>mouseDownAt</td>
<td>//div[#class='dhtmlx_wins_btns_button dhtmlx_button_close_over_pressed']</td>
<td></td>
</tr>
<tr>
<td>clickAt</td>
<td>//div[#class='dhtmlx_wins_btns_button dhtmlx_button_close_over_pressed']</td>
<td>0,0</td>
</tr>
you can try more events until it works, if you are still experiencing problems then make sure your element path is correct (use the selenium firefox IDE and press "Find" button while the FireBug is open and it will colorize the element and it's Html code with yellow glowing color so you can make sure the element path is correct),
another trick is to right click the element and click "Wait for Text..." and copy the path from that command to the click and other commands i stated earlier
if element that you want to click is hidden (for instance a floating layer html) then you can change its attribute display:none to display:block in the firebug (temporary) and that way you can use the rightclick trick to extract the exact path
If you record a "Selenium Builder" script on a page that has an iFrame, I don't believe the recorder will record the switchTo event even though the mouse will have no problem accessing it. So, on replay, without the Selenium switchTo, a selenium even wont be able to click the element unless you manually add a switchTo frame call.
Try accessing the location_once_scrolled_into_view member variable (e.g., as in the following code).
ScrolledPosition = element.location_once_scrolled_into_view
element.click()
For some reason, that quite often allows the click to work even if your code doesn't actually use the position stored there explicitly.
I was able to get Selenium IDE to click the item, even though it doesn't seem to be the correct method in doing so. Below is the HTML for Selenium IDE.
<tr>
<td>mouseDown</td>
<td>css=div.dhtmlx_wins_btns_button.dhtmlx_button_close_default</td>
<td></td>
</tr>
<tr>
<td>clickAt</td>
<td>//div[#class='dhtmlx_wins_btns_button dhtmlx_button_close_over_pressed']</td>
<td>0,0</td>
</tr>
Or you could use //div[#class='dhtmlx_wins_btns_button dhtmlx_button_close_default'] instead of the CSS locator.
I would still appreciate if someone has a better way of getting it to click than this as it still seems like the wrong way to go about it.
Also had same problem with clicking at element <td>. I used method selenium.clickAt(locator, coordString)
f.e.:
selenium.clickAt("element id - easily localized by firebug / firepath [firefox addon]","1.1");

Trying to click on a hyperlink for a row with specific value in Selenium IDE

I'm new to Selenium, There are 2 things I need to do
1. To take a note of the file name on the html but its part of a string so dont know how to concatenate it in Selenium IDE
2. In a table, after searching for the relevant file, I would like to click on a link in one of the other columns for that row. So For the file EMED.pdf, I would like to click the Requested link
HTML snippet:
<td>
<a class="OSfileLink" target="selenium_blank7934" href="/Practice/DownloadFile/8057329d-21df-4a44-baee-2068fc01b7dd" rel="EMED.pdf" style="background-color: transparent;">EMED.pdf</a>
</td>
<td></td>
<td> 27/02/2013 16:19:16 </td>
<td>
<a class="eApproval " data-toggle="modal" data-fileid="8057329d-21df-4a44-baee-2068fc01b7dd" href="#" rel="Requested (28/02/2013)" style="background-color: transparent;">Requested (28/02/2013)</a>
</td>
So far I have :
Command: click
Target: //a[contains(text(),'Requested ')]/following-sibling::a[contains(text(),'EMED.pdf')]
value :
This brings up an error:
[error] Element //a[contains(text(),'Requested ')]/following-sibling::a[contains(text(),'EMED.pdf')] not found
I can "Find" the individual xpath's seperately, but they dont work together. Any help will be appreciated.
Edit
Still no joy with the concatenation, but can work round it with the click being identified.
Any help with concatenation will be much apprciated
* EDIT
Concatenation: For: href="/Practice/DownloadFile/8057329d-21df-4a44-baee-2068fc01b7dd"
I'd like the guid: 8057329d-21df-4a44-baee-2068fc01b7dd from the whole link.
Thanks
Looks like you have your order swapped, try replacing following-sibling with preceding-sibling. Also note you want the <a> nodes, but the following-sibling function is checking the next node after <a>, which is <td>, so you'll need to start with the <td> nodes and check the content of each <a> node within.
Or the other way around, you could change which node you're starting your search with. If you want the "EMED.pdf" but only if the next node is "Requested", try something like this:
//td[contains(a/text(),'EMED.pdf')]/following-sibling::td[contains(a/text(),'Requested')]/a
based on the html you put up, I think this works, I tested it with firefox xpath tester
//.[td[a[contains(text(),'EMED.pdf')]]]//a[contains(text(),'Requested')]