I have 2 selects for setting the expiration date on a credit card and I want to test that the error messaging comes back correctly when the card is expired. The only problem I have is that right now I can’t pick a value that’s expired since the list starts at Jan 2011 which isn’t expired yet. What I’m thinking about doing is using javascript in selenium to inject a known expired value. Anyone have any idea on how to do this or suggestions on a better way to accomplish?
Share
You can use the
storeEvalmethod to run snippets of JavaScript using Selenium. The JavaScript is run in the context of the Selenium object so you needwindow.documentto get the document reference (hence the reason for the first line).This snippet is the JavaScript for adding a new option the
selectelement:Here’s the copy/paste of my Selenium IDE entry for you.
Then you can just have the standard
selectmethod in Selenium to select the option. Of course, you can always dooption.setAttribute('selected',true)in the JavaScript snippet but having Selenium do it will ensure the new value has been selected (since it will fail if it can’t find it).