I'm using the Selenium IDE to store the values of a table in a page in some variables and then type the text in those variables in a text box, one per line.
The problem is that when I loop through the variable ${card} the contents of the variable replace themselves while they should be one at a line.
I would also like to know if I'm using the right tool for doing this. Should I be using the Selenium Webdriver or something else?
Here is the code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="https://es.magiccardmarket.eu/" />
<title>test</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">test</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>https://eu.magiccardmarket.eu/?mainPage=browseUserProducts&idCategory=1&idUser=13786</td>
<td></td>
</tr>
<tr>
<td>store</td>
<td>1</td>
<td>x</td>
</tr>
<tr>
<td>label</td>
<td>target1</td>
<td></td>
</tr>
<tr>
<td>storeTable</td>
<td>//div[#id='siteContents']/div[2]/div[2]/div/form/table.${x}.2</td>
<td>card${x}</td>
</tr>
<tr>
<td>storeEval</td>
<td>new Number(${x}) + 1</td>
<td>x</td>
</tr>
<tr>
<td>gotoIf</td>
<td>storedVars['x'] < 31</td>
<td>target1</td>
</tr>
<tr>
<td>open</td>
<td>http://www.quackit.com/html/codes/html_text_box_code.cfm</td>
<td></td>
</tr>
<tr>
<td>store</td>
<td>1</td>
<td>x</td>
</tr>
<tr>
<td>label</td>
<td>target2</td>
<td></td>
</tr>
<tr>
<td>storeEval</td>
<td>storedVars['card' + storedVars['x']]</td>
<td>card</td>
</tr>
<tr>
<td>type</td>
<td>name=comments</td>
<td>${card}<br /></td>
</tr>
<tr>
<td>storeEval</td>
<td>new Number(${x}) + 1</td>
<td>x</td>
</tr>
<tr>
<td>gotoIf</td>
<td>storedVars['x'] < 31</td>
<td>target2</td>
</tr>
</tbody></table>
</body>
</html>
Type sets the value of an input field. So each time you call type it's only setting it to the 3rd column.
Something like this:
<tr>
<td>storeValue</td>
<td>name=comments</td>
<td>com</td>
</tr>
<tr>
<td>type</td>
<td>name=comments</td>
<td>${com}\n${newvalue}</td>
</tr>
Or you can build up the var and use the type command once.
Frankly I would do this looping in javascript rather than use flow control, which I don't like.
Related
If I run IDE scripts containing assert commands those steps pass when they should not.
If those same steps are executed individually (i.e. selected in the steps pane and then x is pressed) they fail as expected.
If I run those same scripts with the assert commands replaced with verify commands then the steps fail as expected.
I am using Selenium IDE 2.9.1, Firefox 50.0.1, macOS 10.12.3
See attached screenshot and source below.
Anomalous results screenshot
Source:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="https://fe.rel-330.stage.mpb.com/en-uk/" />
<title>New Test</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">New Test</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>https://en.wikipedia.org/wiki/Selenium_(software)</td>
<td></td>
</tr>
<tr>
<td>waitForText</td>
<td>//h3/span</td>
<td>Selenium IDE</td>
</tr>
<tr>
<td>verifyText</td>
<td>//h3/span</td>
<td>wookie</td>
</tr>
<tr>
<td>verifyText</td>
<td>//h3/span</td>
<td>Selenium IDE</td>
</tr>
<tr>
<td>verifyNotText</td>
<td>//h3/span</td>
<td>Selenium IDE</td>
</tr>
<tr>
<td>verifyNotVisible</td>
<td>//h3/span</td>
<td>Selenium IDE</td>
</tr>
<tr>
<td>verifyVisible</td>
<td>//h3/span</td>
<td>Selenium IDE</td>
</tr>
<tr>
<td>verifyEval</td>
<td>storedVars['model1']==storedVars['emailConfirm1']</td>
<td>true</td>
</tr>
<tr>
<td>verifyLocation</td>
<td>https://notwikipedia.com</td>
<td></td>
</tr>
<tr>
<td>assertText</td>
<td>//h3/span</td>
<td>wookie</td>
</tr>
<tr>
<td>assertText</td>
<td>//h3/span</td>
<td>Selenium IDE</td>
</tr>
<tr>
<td>assertNotText</td>
<td>//h3/span</td>
<td>Selenium IDE</td>
</tr>
<tr>
<td>assertNotVisible</td>
<td>//h3/span</td>
<td>Selenium IDE</td>
</tr>
<tr>
<td>assertVisible</td>
<td>//h3/span</td>
<td>Selenium IDE</td>
</tr>
<tr>
<td>assertEval</td>
<td>storedVars['model1']==storedVars['emailConfirm1']</td>
<td>true</td>
</tr>
<tr>
<td>assertLocation</td>
<td>https://notwikipedia.com</td>
<td></td>
</tr>
<tr>
<td>verifyEval</td>
<td>storedVars['model1']==storedVars['emailConfirm1']</td>
<td>true</td>
</tr>
</tbody></table>
</body>
</html>
Apparently Selenium IDE is fairly unreliable. For example, the last command in the following script does not have any effect inside the script but if I double click on it separately it opens the file selection dialog. Why?
Another question, how do I provide file selection with a next command?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="https://www.gumtree.com/" />
<title>gumtree</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">gumtree</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>https://my.gumtree.com/postad</td>
<td></td>
</tr>
<tr>
<td>waitForPageToLoad</td>
<td>5000</td>
<td></td>
</tr>
<tr>
<td>clickAt</td>
<td>//form[#id='frmSyi']/div/div/div/div/nav/ul/li[2]/div/span[2]</td>
<td></td>
</tr>
<tr>
<td>waitForPageToLoad</td>
<td>500</td>
<td></td>
</tr>
<tr>
<td>clickAt</td>
<td>//form[#id='frmSyi']/div/div/div/div/div/div/div/div/ul/li[10]/span</td>
<td></td>
</tr>
<tr>
<td>waitForPageToLoad</td>
<td>500</td>
<td></td>
</tr>
<tr>
<td>clickAt</td>
<td>//form[#id='frmSyi']/div/div/div/div/div/div[2]/div/div/ul/li[2]/span</td>
<td></td>
</tr>
<tr>
<td>waitForPageToLoad</td>
<td>500</td>
<td></td>
</tr>
<tr>
<td>clickAt</td>
<td>//form[#id='frmSyi']/div/div/div/div/div/div[3]/div/div/ul/li[4]/span</td>
<td></td>
</tr>
<tr>
<td>pause</td>
<td>500</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>id=continueButton</td>
<td></td>
</tr>
<tr>
<td>pause</td>
<td>500</td>
<td></td>
</tr>
<tr>
<td>clickAt</td>
<td>link=Add image</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
ClickAt is a specialised command for clicking coordinates. So you are using it in a wrong way. You should use regular click, or doubleClick or (in a very special case) clickAt with providing coordinates string.
File uploading is not so straight-forward. You should find an input that contains file name for uploading. Send a file-name to it with type command or javascript. And finally initiate uploading. Like:
type | id=hiddenInputForFileName | /path_to_your_file/your_file.lol
click | id=startUploadingButton
That's an example. Your code will depend on the file uploading form design. I hope it will help. If it won't please provide the html of your page and I will post the code for your situation.
I have a Selenium test to run on RasPi. I have a problem, in that the command I use opens up iceweasel windows with open Selenium GUI, but nothing happens. I presss run test button and nothing happens then either. Also, I was hoping in the long run to add this command to crontab to perform it on a weekly basis, so I would like it to require no user input at all.
Here is my test:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="https://better.legendonlineservices.co.uk/" />
<title>Body_Pump</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">Body_Pump</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>/enterprise/account/login</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>id=login_Password</td>
<td>**********</td>
</tr>
<tr>
<td>type</td>
<td>id=login_Email</td>
<td>***********#*********.com</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>id=login</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>css=a.TextMembers</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>id=behSubmit</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>xpath=(//input[#name='activity'])[9]</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>id=actSubmit</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>id=bottomsubmit</td>
<td></td>
</tr>
<tr>
<td>selectFrame</td>
<td>TB_iframeContent327</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>id=slot13257070</td>
<td></td>
</tr>
<tr>
<td>selectWindow</td>
<td>name=TB_iframeContent415</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=OK</td>
<td></td>
</tr>
<tr>
<td>selectWindow</td>
<td>null</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>id=btnPayNow</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>id=btnPayNow</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
Here is the command I run Selenium with:
java -jar selenium-server-standalone-2.52.0.jar -htmlSuite "*firefox" "http://www.google.com/" "/home/pi/Documents/Body_Pump.html" "/home/pi/Documents/Log.html"
When I run this command, this interface pops up:
Selenium interface
After it appears, nothing happens. Whatever I click nothing happens anyway. Any help would be much appreciated!
The answer to my problem turned out to be the fact that I was trying to run a Selenium "test case" instead of a "test suite". It can be easily done through IDE, by opening the test case and saving a suite in the File drop-down menu.
I now however have a problem in that my test case seems to be opening through the command but not working the same way as when I just run it through the IDE.
I am using Selenium to record my actions on a webpage, however, when I play the test case, there is an click action throwing error: Element is not currently visible and so may not be interacted with. However, I am sure that button is visible, and here is html for it:
<button class="btn btn-success btnSubmit" style="font-size: 1.9em; width: 100%; height: 2em; margin-top: 20px;" type="submit"> Get Your Report </button>
Also, here is my test script for Selenium IDE:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://hra.case.edu/" />
<title>New Test</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">New Test</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>/</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=Get Started</td>
<td></td>
</tr>
<tr>
<td>keyPress</td>
<td>name=searchFirstName</td>
<td>Tiancheng</td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//div[#id='content']//tbody[#id='select_user']/tr[1]//a</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>//div[#id='content']//tbody[#id='select_user']/tr[1]//a</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>id=answer_heightFoot</td>
<td>5</td>
</tr>
<tr>
<td>type</td>
<td>id=answer_heightInch</td>
<td>11</td>
</tr>
<tr>
<td>type</td>
<td>id=answer_weight</td>
<td>222</td>
</tr>
<tr>
<td>select</td>
<td>id=answer_bodySize</td>
<td>label=Medium</td>
</tr>
<tr>
<td>click</td>
<td>id=answer_diabetes_no</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>link=Other</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>id=next</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>//button[#type='submit']</td>
<td></td>
</tr>
<tr>
<td>verifyElementPresent</td>
<td>//button[#type='submit']</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//button[#type='submit']</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
Anyone has an idea of why?
Thanks in advance!
Some webelement may be present at DOM but be invisible at the same time. So, after you perform some action use waitForVisible method to wait for element to become visible and interactible
UPDATE: #Kees de Kooter, here's the working example
<tr>
<td>open</td>
<td>http://stackoverflow.com/</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=.js-help-button</td>
<td></td>
</tr>
<tr>
<td>waitForElementPresent</td>
<td>css=.js-help-button</td>
<td></td>
</tr>
<tr>
<td>waitForVisible</td>
<td>css=.js-help-dialog</td>
<td></td>
</tr>
Configuration Manifesting
Windows 7.
FireFox 22.
RAM 2 GB.
The following error occurs when we try to click on login button:-
[error] Unexpected Exception: fileName -> chrome://selenium-ide/content/selenium-core/scripts/htmlutils.js, lineNumber -> 309, columnNumber -> 8
Source code:-
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://foxtel-cms.local/" />
<title>TC_4_RT</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">TC_4_RT</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>/</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>id=edit-name</td>
<td>qa_editor</td>
</tr>
<tr>
<td>type</td>
<td>id=edit-pass</td>
<td>qa_editor</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>id=edit-submit</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=Foxtel Content(active tab)</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=TC_3_RT_148</td>
<td></td>
</tr>
<tr>
<td>verifyText</td>
<td>link=Summary(active tab)</td>
<td>Summary(active tab)</td>
</tr>
<tr>
<td>verifyText</td>
<td>link=Overview</td>
<td>Overview</td>
</tr>
<tr>
<td>verifyText</td>
<td>link=Rotten Tomatoes</td>
<td>Rotten Tomatoes</td>
</tr>
<tr>
<td>verifyText</td>
<td>link=Edit</td>
<td>Edit</td>
</tr>
<tr>
<td>verifyText</td>
<td>link=Edit Genre</td>
<td>Edit Genre</td>
</tr>
<tr>
<td>verifyText</td>
<td>link=Edit Other Metadata</td>
<td>Edit Other Metadata</td>
</tr>
<tr>
<td>verifyText</td>
<td>link=Edit Synopsis</td>
<td>Edit Synopsis</td>
</tr>
<tr>
<td>verifyText</td>
<td>link=Revisions</td>
<td>Revisions</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=Summary(active tab)</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=Overview</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=Rotten Tomatoes</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=Edit</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=Edit Genre</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=Edit Other Metadata</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=Edit Synopsis</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=Revisions</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=Log out</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
My Question:- Is there any solution for this error?
there is a fix (that works fine for my test case), see also http://code.google.com/p/selenium/issues/detail?id=5841: http://release.seleniumhq.org/selenium-ide/2.1.0/selenium-ide-2.1.0.xpi
This error is probably due to FF version 22. I uninstalled my FF 22 and reinstalled firefox 21 and it is working fine for me.