0

I do software testing for my company's e-commerce platform, and am trying to automate our checkout process testing. For multiship option, each line item has a separate "Add an address" link. I can easily target the first one, but how can I target the 2nd/3rd/etc? I am NOT a developer, so any help would be very helpful. This is a snippit of the html for one of those links add an address link -

<div class="editaddress eleven">
    <a class="add dialogify desktop" title="Add New Address" data-dlg-options="{ "width" :    "385px", "dialogClass" : "address-add-edit multishipping", "title" : "Add New Address"}" href="https://XXXXXXXXXXX/COShippingMultiple-EditAddress?i=bcvVIiaagN4ckaaada3w22QH7J"> Add New Address </a>

All of the addresses are "editaddress eleven." Don't know who decided that :-)

Any help you can provide would be wonderful. I am trying my best to learn webdriver. Thanks!

2
  • And what does the code for targetting the 1st one look like? Commented Aug 2, 2013 at 14:41
  • Hi, can you show a bit more of the html code? You need some locators which will uniquely identify one line item but not the others; but without seeing the html, it's hard for us to make useful suggestions. Commented Aug 5, 2013 at 13:40

3 Answers 3

3

read the docs, I think the function names speak for themselves.

#variable "driver" is the current selenium webdriver.

div = driver.find_element_by_css_selector('div.editaddress.eleven')

links = div.find_elements_by_css_selector('a.add.dialogify.desktop')

for link in links:
    #do_something
Sign up to request clarification or add additional context in comments.

Comments

0

Assuming all we know is the 'Add New Address' title we could (python example) create a list of elements matching this rule and iterate through it.

lines = driver.find_elements_by_css_selector("a[title='Add New Address']")

Comments

0

you want xpath selectors for this here you go :

//a[@title='Add New Address'][i]

Xpath is a relative selector, the // tells the selector to look anywhere in the document for an "a" type element which is what you have listed, the [@title='Add New Address"] says only return those "a" type elements with a title of "Add New Address". The last part is an index reference number... I am assuming you have more than one Add New Address element, as long as they are similar Elements, replace i with the # of the element you want, relative to its appearance in the document, from the top down.

//a[@title='Add New Address'] - will get you all of the elements
//a[@title='Add New Address'][1] - will get you the first
//a[@title='Add New Address'][2] - will get you the second

so on and so forth

what you should do is

//count number of elements on the page and store them as an integer

int numberofElements = selenium.getXPathCount("//a[@title='Add New Address']")

//loop through the elements, grabbing each one and doing whatever you please with them

for(i=0;i<numberofElements;i++){
  selenium.click("//a[@title='Add New Address']["+i+"]");
  //insert rest of commands you want selenium to do for every one of the elements that are   on the page
 }

hope this helps Jake

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.