Solved

selenium script issues to recognize jsf elements

Posted on 2013-12-12
14
959 Views
Last Modified: 2013-12-24
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
0
Comment
Question by:gudii9
  • 8
  • 6
14 Comments
 
LVL 6

Expert Comment

by:Craig Kehler
ID: 39715455
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.
0
 
LVL 7

Author Comment

by:gudii9
ID: 39716982
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
0
 
LVL 6

Expert Comment

by:Craig Kehler
ID: 39717386
How do i do that.  please advise

TargetDropDown
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/
0
 
LVL 7

Author Comment

by:gudii9
ID: 39717842
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
0
 
LVL 6

Expert Comment

by:Craig Kehler
ID: 39717911
0
 
LVL 7

Author Comment

by:gudii9
ID: 39717932
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
0
 
LVL 7

Author Comment

by:gudii9
ID: 39717965
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
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 6

Expert Comment

by:Craig Kehler
ID: 39718102
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.
0
 
LVL 7

Author Comment

by:gudii9
ID: 39727251
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.
0
 
LVL 6

Expert Comment

by:Craig Kehler
ID: 39727440
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.
0
 
LVL 7

Author Comment

by:gudii9
ID: 39727503
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
0
 
LVL 7

Author Comment

by:gudii9
ID: 39727816
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
0
 
LVL 7

Author Comment

by:gudii9
ID: 39727993
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
0
 
LVL 6

Accepted Solution

by:
Craig Kehler earned 500 total points
ID: 39728265
Please read through the documentation as it answers many of the questions you are asking. http://docs.seleniumhq.org/docs/03_webdriver.jsp is the documentation for webdriver, which was linked on the last page I sent you under
For More information on Selenium WebDriver, please see the documentation and Remote Control to WebDriver Migration Notes.

The questions about the IDE are on the page I linked to you earlier http://www.seleniumhq.org/docs/02_selenium_ide.jsp

I'm happy to help with technical hurdles but I this will take a very long time unless you try it out a bit and get through the basic questions answered in their documentation.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now