How do i Execute javascript user-extention.js file in selenium directly? - selenium

How do i Execute javascript in selenium directly?
How we use command in java script?
In selenium Ide i sotre in selenium core extension (User-extention.js) file and
which file store in selenium ide extention....
I also run the below script but i can''t get result...
<body
<table>
<tr>
<td>open</td>
<td>https://www.google.com</td>
<td></td>
</tr>
<tr>
<td>store</td>
<td>40</td>
<td></td>
</tr>
<tr>
<td>store</td>
<td>0</td>
<td></td>
</tr>
<tr>
<td>while</td>
<td>storedVars.looptimes < = 20</td>
<td></td>
</tr>
<tr>
<td>storeEval</td>
<td>selenium.browserbot.getCurrentWindow().scrollTo(o,${i})</td>
<td></td>
</tr>
<tr>
<td>store</td>
<td>javascript{storedVars.looptimes++;}</td>
<td></td>
</tr>
<tr>
<td>storeEval</td>
<td>${i}+40</td>
<td></td>
</tr>
<tr>
<td>endWhile</td>
<td></td>
<td></td>
<tr>
</table>
</body>
But i am getting error
[error] Unexpected Exception: SyntaxError: syntax error. fileName -> chrome://flowcontrol/content/extensions/goto-sel-ide.js?1392885586314, lineNumber -> 134

Please check the code I have given.
http://seleniumworks.blogspot.in/2014/01/selenium-ide-data-driven.html
Also make sure,
Active developer tools and
Enable experimental features
checkboxes are Enabled.
Prashanth Sams | seleniumworks.com

Related

Selenium goBack and wait

I have this selenium test (a part of it).
<tbody>
<tr>
<td>open</td>
<td></td>
<td>localhost:8091</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=Rest objects</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>xpath=(//a[contains(text(),'Show')])[3]</td>
<td></td>
</tr>
<tr>
<td>assertText</td>
<td>xpath=(//div[not(div)][1])</td>
<td>ID: 2</td>
</tr>
<tr>
<td>goBack</td>
<td></td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>xpath=(//a[contains(text(),'Show')])[5]</td>
<td></td>
</tr>
<tr>
<td>goBack</td>
<td></td>
<td></td>
</tr>
</tbody>.
I use Selenium IDE in Firefox. When I run it slowly (toggle speed), it works well. However, when I try to run it faster, I get error at the step <td>clickAndWait</td> after <td>goBack</td>. The log says,
Element xpath=(//a[contains(text(),'Show')])[5] not found.
My questions, how to go back and wait until the page is loaded before I perform other actions.
You have to use waitForPageToLoad command adter click on element till the page loaded and then perform other actions
Use Below code
<tr>
<td>click</td>
<td>xpath=(//a[contains(text(),'Show')])[5]</td>
<td></td>
</tr>
<tr>
<td>waitForPageToLoad</td>
<td>10000</td>
<td></td>
</tr>
Thanks (#Trimantra Software Solution).
waitForPageToLoad this is what I needed.
From documentation:
waitForPageToLoad(timeout)
Arguments:
timeout - a timeout in milliseconds, after which this command will return with an error
Waits for a new page to load.
This is my solution, I used waitForPageToLoad after goBack.
<tbody>
<tr>
<td>open</td>
<td></td>
<td>localhost:8091</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=Rest objects</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>xpath=(//a[contains(text(),'Show')])[3]</td>
<td></td>
</tr>
<tr>
<td>assertText</td>
<td>xpath=(//div[not(div)][1])</td>
<td>ID: 2</td>
</tr>
<tr>
<td>goBack</td>
<td></td>
<td></td>
</tr>
<tr>
<td>waitForPageToLoad</td>
<td>800</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>xpath=(//a[contains(text(),'Show')])[5]</td>
<td></td>
</tr>
<tr>
<td>goBack</td>
<td></td>
<td></td>
</tr>
</tbody>
I see a goBackAndWait() variant of this command. That might work for you.
Typically I'd advise using a waitFor to ensure the page is back to where you want. Simplest that may work is waitForTitle if possible.
waitForElementPresent & waitForText also good ones to look at.

Selenium IDE - [error] Element css=button.ng-binding.active not found

I'm trying a basic webpage navigation and each time, I run the recorded scrip it throws the error as defined in the title.
Environment - Selenium IDE - 2.9.1
Browser - Mozilla
<tr>
<td>open</td>
<td>/samplequestions</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=button.ng-binding.active</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=button.ng-binding</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=button.ng-binding</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//button[2]</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>name=myrate</td>
<td>1000</td>
Could someone help me out what I may have to change ?
As far as now 'ng-binding' is an AngularJS locator and selenium doesn't support it.
If you need to automate Angular application then it is better to you Protrator and using it you can find element like this:
element(by.binding('value'));

Selenium IDE wont click on dynamic id

I'm having trouble getting a link clicked on Selenium IDE.
The id is picked from the itteration in a while loop but i can't get the ID echo'ed in somehow.
This is my code:
<tr>
<td>open</td>
<td>/list</td>
<td></td>
</tr>
<tr>
<td>storeAllLinks</td>
<td>linkArray</td>
<td></td>
</tr>
<tr>
<td>getEval</td>
<td>0</td>
<td>index</td>
</tr>
<tr>
<td>while</td>
<td>index < 10;</td><!-- should be array length but that wont word eighter, problem for later -->
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>id=${index}</td>
<td></td>
</tr>
<tr>
<td>getEval</td>
<td>index++;</td>
<td></td>
</tr>
<tr>
<td>pause</td>
<td>1000</td>
<td></td>
</tr>
<tr>
<td>endWhile</td>
<td></td>
<td></td>
</tr>
Anny clues on whats going wrong would be great help.
Thank you in advance!
You can locate link by its text. Use of Xpath and link text might help you.
Or please share part of HTML.

Selenium IDE getting id from url parameter?

I am struggling with getting the id from a url in selenium ide please could you assist me Thanks. When I echo the store location it removes the equals? PLease see the comments for the output below. Thanks for any help given.
When I run the ide tests I run it through webdriver and on internet explorer but i dont think this should make much difference.
<tr>
// gets http//website.co.uk/index.php?main_detail_id=123456789123456
<td>storeLocation</td>
<td>loc</td>
<td></td>
</tr>
<tr>
//prints http//website.co.uk/index.php?main_detail_id123456789123456
<td>echo</td>
<td>${loc}</td>
<td></td>
</tr>
<tr>
//no errors have also tried split '?'
<td>storeEval</td>
<td>"${loc}".split('=')[2]</td>
<td>mainid</td>
</tr>
<tr>
//prints nothing.
<td>echo</td>
<td>${mainid}</td>
<td></td>
</tr>
Below is code with help of that you can get ID from URL
<tr>
<td>store</td>
<td>http//website.co.uk/index.php?main_detail_id=123456789123456</td>
<td>test</td>
</tr>
<tr>
<td>store</td>
<td>1</td>
<td>delimiter</td>
</tr>
<tr>
<td>store</td>
<td>javascript{storedVars['test'].split('=')[storedVars['delimiter']]}</td>
<td>vv</td>
</tr>
<tr>
<td>echo</td>
<td>${vv}</td>
<td></td>
</tr>

Selenium IDE testing all links

I'm trying to use Selenium IDE to test a web app. On one page, there are several links which trigger modal windows. I'd like to test ALL the links on the page to ensure that ALL cause modals to pop up.
Each link has a class "modal" so I thought I could just change the target value in IDE css=a.modal but that finds only the first link.
I've found a few solutions but they use Selenium RC with Java/Python and those can't be directly translated to the IDE.
I understand the IDE is not as powerful but I'm setting this up for a non-programmer to use and up till now, it's been really simple for them.
i had to read up a lot and i want to thank #ohaal and #aleh for their inputs. i used their suggested links as well as some more external reading to reach the solution like so:
<tr>
<td>open</td>
<td>/logout</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=Forum</td>
<td></td>
</tr>
<tr>
<td>storeXpathCount</td>
<td>//p[3]/span/a[contains(#class, 'modal')]</td>
<td>users</td>
</tr>
<tr>
<td>store</td>
<td>1</td>
<td>i</td>
</tr>
<tr>
<td>while</td>
<td>storedVars.i<=storedVars.users</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//descendant::a[contains(#class, 'modal')][${i}]</td>
<td></td>
</tr>
<tr>
<td>waitForText</td>
<td>css=h2</td>
<td>You are not logged in</td>
</tr>
<tr>
<td>click</td>
<td>css=#cross_button > a > img</td>
<td></td>
</tr>
<tr>
<td>store</td>
<td>javascript{storedVars.i++}</td>
<td></td>
</tr>
<tr>
<td>endWhile</td>
<td></td>
<td></td>
</tr>
i'm not selecting any one answer as all of them contributed to the final solution.
Use a while loop, and this XPath expression as a locator: //a[contains(#class, 'modal')]
//a[contains(#class, 'modal')][1], //a[contains(#class, 'modal')][2] and so on should point to the links you're after.
See this link for more information on how to do while loops in Selenium IDE if you are unfamiliar with it.
Try this (you have to download this extension):
<tr>
<td>storeCssCount</td>
<td>css=a.modal</td>
<td>links</td>
</tr>
<tr>
<td>store</td>
<td>0</td>
<td>i</td>
</tr>
<tr>
<td>label</td>
<td>l1</td>
<td></td>
</tr>
<tr>
<td>getEval</td>
<td>storedVars.i++</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//descendant::a[contains(#class, 'modal')][${i}]</td>
<td></td>
</tr>
<tr>
<td>gotoIf</td>
<td>--storedVars.links</td>
<td>l1</td>
</tr>
Insert your assertions and probably pop-ups closings before last command (gotoIf).