- shutey
- Posts : 2
Join date : 2014-03-24
Validating 'random' text based on xpath
Tue Mar 25, 2014 4:36 pm
Hi all,
Sorry if this has been asked previously, but I've not been able to locate the thread that contains this question.
I'm trying to expand on my knowledge of Selenium IDE as I look to do more and more with the tool, along with expanding the capabilities to meet our website validation needs.
Basically, the scenario is event searching within a heavily content managed site. I've been able to build the script to pick up any event within a table and carry out a certain function, mitigating the need to have specific content in an ever changing environment.
For content served within a table, i have managed to write the script as:
Command Target Value
open /events
storeTable css=table.ce-list.1.0 eventA
storeTable css=table.ce-list.1.0 eventB
verifyElementPresent link=${eventA}
verifyElementPresent link=${eventB}
clickAndWait link=${eventA}
This allows me to select any event (or in this case the top two) that are served within the table.
We then have another page that handles events based on a search, these are served via divs which means i am unable to use the same logic for these as above. In this case, i have had to use the xpath to select an item as it appears and not based on the item name (okay as long as there is one!).
Question 1 - Is it possible to use an IF statement within IDE? For example, "IF xpath isn't displayed do this".
Answer - Yes, i am able to use IF statements with the aid of (http)51elliot.blogspot.cz/2008/02/selenium-ide-goto.html. However i'm still trying to get my head around the commands)
I am then trying to validate various text values upon event selection/ application. For example, the script so far looks like:
Command Target Value
waitForElementPresent xpath=/html/body/div/div[4]/div/div[2]/div[2]/div/div/div/div[2]/div/p/span[2]/strong/a
click xpath=/html/body/div/div[4]/div/div[2]/div[2]/div/div/div/div[2]/div/p/span[2]/strong/a
verifyText I would like you to arrange my place
click id=registrationtype_1_e5
clickAndWait css=input.cesubmit
This then takes me to the event signup form, where some text and fee value is pre-populated based on content/ selection made. So, in this case, i have the event name and fee ("The registration fee for TEST EVENT is £25." appear at the top of the form which needs to be validated.
Seeing as i'm using a random event based on the xpath to get to this point, this text will potentially change when new events get created via the CMS. So "Test Event" and a fee of "£25" could change to "Swimming with sharks" with a fee of "£300". What i need to do is to be able to validate a couple of things which i'm assuming will need to be done via xpath?
1) there is an event name being populated
2) there is an event fee being populated
3) i want to also be able to validate a specific fee, say a value of £25 or a string contains £
So this is where i ask how this is possible?
So far, i'm using:
Command Target
verifyElementPresent xpath=/html/body/div/div[4]/div/div/div[3]/div/form/div/fieldset/div/label/strong (this is for event name)
verifyElementPresent xpath=/html/body/div/div[4]/div/div/div[3]/div/form/div/fieldset/div/label/strong[2] (this is for event fee)
If i knew the event was going to be the same each time, then i would have used the verifyText/ assertText commands and given it a specific target and value. If i use the assertText command, the target for the specific text item would be "//div[@id='theregistrationfeeforstrongeventnamestrongisstrongeventfeestrong']/label/strong[2]" and value £25 ~ could i use the same command/ target but the value would be anything containing £? If so, how?
Sorry if this has been asked previously, but I've not been able to locate the thread that contains this question.
I'm trying to expand on my knowledge of Selenium IDE as I look to do more and more with the tool, along with expanding the capabilities to meet our website validation needs.
Basically, the scenario is event searching within a heavily content managed site. I've been able to build the script to pick up any event within a table and carry out a certain function, mitigating the need to have specific content in an ever changing environment.
For content served within a table, i have managed to write the script as:
Command Target Value
open /events
storeTable css=table.ce-list.1.0 eventA
storeTable css=table.ce-list.1.0 eventB
verifyElementPresent link=${eventA}
verifyElementPresent link=${eventB}
clickAndWait link=${eventA}
This allows me to select any event (or in this case the top two) that are served within the table.
We then have another page that handles events based on a search, these are served via divs which means i am unable to use the same logic for these as above. In this case, i have had to use the xpath to select an item as it appears and not based on the item name (okay as long as there is one!).
Question 1 - Is it possible to use an IF statement within IDE? For example, "IF xpath isn't displayed do this".
Answer - Yes, i am able to use IF statements with the aid of (http)51elliot.blogspot.cz/2008/02/selenium-ide-goto.html. However i'm still trying to get my head around the commands)
I am then trying to validate various text values upon event selection/ application. For example, the script so far looks like:
Command Target Value
waitForElementPresent xpath=/html/body/div/div[4]/div/div[2]/div[2]/div/div/div/div[2]/div/p/span[2]/strong/a
click xpath=/html/body/div/div[4]/div/div[2]/div[2]/div/div/div/div[2]/div/p/span[2]/strong/a
verifyText I would like you to arrange my place
click id=registrationtype_1_e5
clickAndWait css=input.cesubmit
This then takes me to the event signup form, where some text and fee value is pre-populated based on content/ selection made. So, in this case, i have the event name and fee ("The registration fee for TEST EVENT is £25." appear at the top of the form which needs to be validated.
Seeing as i'm using a random event based on the xpath to get to this point, this text will potentially change when new events get created via the CMS. So "Test Event" and a fee of "£25" could change to "Swimming with sharks" with a fee of "£300". What i need to do is to be able to validate a couple of things which i'm assuming will need to be done via xpath?
1) there is an event name being populated
2) there is an event fee being populated
3) i want to also be able to validate a specific fee, say a value of £25 or a string contains £
So this is where i ask how this is possible?
So far, i'm using:
Command Target
verifyElementPresent xpath=/html/body/div/div[4]/div/div/div[3]/div/form/div/fieldset/div/label/strong (this is for event name)
verifyElementPresent xpath=/html/body/div/div[4]/div/div/div[3]/div/form/div/fieldset/div/label/strong[2] (this is for event fee)
If i knew the event was going to be the same each time, then i would have used the verifyText/ assertText commands and given it a specific target and value. If i use the assertText command, the target for the specific text item would be "//div[@id='theregistrationfeeforstrongeventnamestrongisstrongeventfeestrong']/label/strong[2]" and value £25 ~ could i use the same command/ target but the value would be anything containing £? If so, how?
- ccoxMaster
- Posts : 205
Join date : 2012-01-06
Age : 39
Location : Denver, CO
Re: Validating 'random' text based on xpath
Thu Mar 27, 2014 9:46 am
Sorry if I'm a little lost in what you're asking. If you are trying to assert that a String contains some text, you can use the getEval/storeEval commands to execute javascript. With this you can use the .contains() function and return true if it is a match. Store your result as a variable and assert that variable is true.
Also it is helpful to only include relevant information to your question in your post.
Also it is helpful to only include relevant information to your question in your post.
- jgohel
- Posts : 7
Join date : 2016-06-08
Re: Validating 'random' text based on xpath
Wed Jun 08, 2016 7:30 pm
your first code is wrong so I replace with this
Command Target Value
open /events
storeTable css=table.ce-list.1.0 eventA
storeTable css=table.ce-list.1.0 eventB
verifyElementPresent ${eventA}
verifyElementPresent ${eventB}
clickAndWait ${eventA}
Now its works better than previous
Command Target Value
open /events
storeTable css=table.ce-list.1.0 eventA
storeTable css=table.ce-list.1.0 eventB
verifyElementPresent ${eventA}
verifyElementPresent ${eventB}
clickAndWait ${eventA}
Now its works better than previous
- How to get the tittle of a object (not window), bcz title holds the full text but inner text holds only 25 char of text (in RC and Webdriver)
- Text Generation based on button click
- How do i get the ID or Xpath of Text from Dynamic table?
- Tree View: Expanding a node by searching for element by text using xpath
- How Xpaths works in Selenium and What is the difference between native Xpath and absolute xpath and relative xpath.
Permissions in this forum:
You cannot reply to topics in this forum