Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

selenium script issues to recognize jsf elements

Hi,

I am using mozilla selenium plugin to do some regresssion testing.

I recorded a script by searching on vendor name.



When i replay the scripts i am getting errors as below for some jsf Div elements, text boxes etc

Element //tbody[@id='mainForm:form:result_data']/tr[4]/td/div not found


How do i resolved these errors.(in other words how do I teach to selenium to recognize these jsf elements.It is recognizing buttons etc fine but not some elements like above. )

Basically in search.xhtml i search on Vendor Name 'xyz' and srr at bottom of search.xhtml page i get 2 results with say 3 columns
Vendor Name            vendor address            vendor city
xyz                                  123 main st                Minneapolis
xyz                                   123 Broad St              Boston

I am selecting second vendor record (xyz                                   123 Broad St              Boston)

That click is not getting recognized when i replay the selenium regression script with error
Element //tbody[@id='mainForm:form:result_data']/tr[4]/td/div not found

How do i put different assert statements and validate drop down fields to have specific defalt values.

please advise
Any links resources ideas highly appreciated. Thanks in advance
Avatar of Craig Kehler
Craig Kehler
Flag of United States of America image

Have you tried stepping through the script each command at a time and waiting for the page to finish loading? Often when playing things back at full speed you can encounter timing issues with asyncs or delayed content.

You can step through by double clicking each step or place a breakpoint right before the failure point, highlight the test case and click Find next to the target.

Also you can use the slider in the top left to slow down the execution speed.

You may find the waitFor and verifyElementPresent actions useful. I recommend re-recording your test and seeing if there have been any slight changes in your target selector.

Finally when selecting targets try to avoid XPaths when possible. In this case you may not be able to (since it's in a table) but I would try to target things by id or name before using css or xpaths. There is a drop down on the target field that will let you see what selectors it has identified.
Avatar of gudii9

ASKER

Finally when selecting targets try to avoid XPaths when possible. In this case you may not be able to (since it's in a table) but I would try to target things by id or name before using css or xpaths.

How do i do that.  please advise

Also once i search i see 2 records i get a button which says download to a excel spreadsheet. When i click that button i see popup with excel sheet auto generated name and radio button options to either open or save. I want to save to let us say C:/Test folder in my windows machine (vendor.xlsx) and then open vendor.xlsx and see the spreadsheet has all correct data as below

Vendor Name            vendor address            vendor city
xyz                                  123 main st                Minneapolis
xyz                                   123 Broad St              Boston


But selenium is not recognizing the 'Save' button click and also it is not replaying my action of going to C:/Test and opening vendor.xlsx to validate the data. How can i achieve it. Please advise
How do i do that.  please advise

User generated image
However if you want to start saving data to files and validating it, you'll need to move from the IDE into webdriver tests in the language of your choice. While the IDE works well for simple tests and often can be used to get a framework setup for your tests you will need to use a real programming language with webdriver to do more advanced functions. See http://www.seleniumhq.org/
Avatar of gudii9

ASKER

Have you tried stepping through the script each command at a time and waiting for the page to finish loading? Often when playing things back at full speed you can encounter timing issues with asyncs or delayed content.

You can step through by double clicking each step or place a breakpoint right before the failure point, highlight the test case and click Find next to the target.


how to do it
Avatar of gudii9

ASKER

Element id=mainForm:form:j_idt58 not found

I am getting above error with text box where i am searching Vendor Name 'xyz'


It works sometimes. It does not work sometimes.
You may find the waitFor and verifyElementPresent actions useful.
How to add the waitFor in my script

Let us say my script is as below

Command	Target	Value
open	https://www.google.co.in/	
clickAndWait	css=#gb_2 > span.gbts	
assertTitle	Google Images	
clickAndWait	css=#gb_8 > span.gbts	
assertTitle	Google Maps	
clickAndWait	css=#gb_78 > span.gbts	
assertTitle	Google Play	

Open in new window


When i right click there is option to add new command

but i am not able to add the new blank command.

I copy pasted one other old command to the top.

which has
command target value
waitFor         -      5000

I gave as above 5000 milliseconds by ignoring targer field.

But some reasone script is complainging saying no target specified something like that.

Below command they mentioned gve target as 5000 instead of value 5000

command target value
pause       5000  -

It seems waited for 5 seconds but still it is not recognizing the jsf element with error
when i select the table row element
 Element id=mainForm:j_idt499:form_0:j_idt539_button not found


Please advise
Avatar of gudii9

ASKER

I got other error recognizing the text box as below
Element id=mainForm:form:vendorNBR not found

which was working fine earlier.

not sure what is the issue. please advise
waitFor requires a target element so you can use it to wait for the target before you perform an action like:
waitFor css=#gb_2 > span.gbts
clickAndWait      css=#gb_2 > span.gbts

The adding of new commands is a little weird. After you select insert new command you have to click on the blank field it makes and then select the command box.

As for the targets changing over time, it will be difficult for me to help without seeing the site in question. You have to find a way to reliably locate the targets. In the past I've had to use the webdriver implementation to reliably read large tables and perform actions on them. That is why I suggested you start investigating graduating from the IDE to webdriver to get more reliable control.
Avatar of gudii9

ASKER

how is using 'pause' command diffferent frm waitFor.


command target value
pause       5000  -

Above pause command did not help either.
Please advise.

Are there any selenium existing bugs to recognize jsf elements. where to find selenium know issues, bugs to check before wasting time on trying to implement something that eventually does not work. I wonder how tests start of the day first time and later will not work.
Do I need to remove browser cache and open empty mozilla tab everytime i run the tests.

finally table row gtting recognized now after restarting and removing cache..but now button not geting recognized
Element id=mainForm:j_idt499:form_0:j_idt539_button not found

similar buttons in other tests working OK. Not sure how to fix this.

Is webdriver is open source plugin tool like selenium which i can add to mozilla browser.

I am a developer do not know much about webdriver. please advise.
Pause is basically a sleep, waitFor tests for the existence of a condition.

I think you may be seeing issues with how you are trying to select the target. There are better ways of experimenting with this in webdriver.

Webdriver is a much more robust developer tool than the record and playback IDE.

http://www.seleniumhq.org/projects/webdriver/

You will find it much more useful.
Avatar of gudii9

ASKER

Selenium 1.0 + WebDriver = Selenium 2.0

i see my selenium version is 2.4.0

Does it mean i already have webdriver embedded in my selenium mozilla plugin?

How do I verify. please advise
Avatar of gudii9

ASKER

i still get issues with buttons as below

Element id=mainForm:j_idt499:form_0:j_idt539_button not found


How can i fix button recognization issues. Please advise
Avatar of gudii9

ASKER

clickAndWait seems far better compared to click I observed. What is the difference. What is the difference between
Command
Target
Value

that we specify for each new command.

Target and values seems similar to me.

If I change the environment from local to QA or to Production does these scripts works. Or do I need to rerecord in higher environments. Please advise
ASKER CERTIFIED SOLUTION
Avatar of Craig Kehler
Craig Kehler
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial