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!

4

3 回答 3

3

阅读文档,我认为函数名称不言自明。

#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
于 2013-08-02T14:55:53.033 回答
0

假设我们只知道“添加新地址”标题,我们可以(python 示例)创建一个匹配此规则的元素列表并遍历它。

lines = driver.find_elements_by_css_selector("a[title='添加新地址']")

于 2013-08-02T14:56:43.957 回答
0

你想要xpath选择器在这里你去:

//a[@title='添加新地址'][i]

Xpath 是一个相对选择器, // 告诉选择器在文档中的任何位置查找您列出的“a”类型元素,[@title='Add New Address"] 表示只返回那些“a”键入标题为“添加新地址”的元素。最后一部分是索引参考编号...我假设您有多个添加新地址元素,只要它们是相似的元素,将 i 替换为 # of你想要的元素,相对于它在文档中的外观,从上到下。

//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

等等等等

你应该做的是

//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
 }

希望这可以帮助杰克

于 2013-08-02T16:26:52.347 回答