我遇到了一个元素列表的问题:
arialabel = (list([my_elem.get_attribute("aria-label") for my_elem in WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, "div.MatchModeQuestionGridTile-content>div[aria-label]")))]))
['solid', 'massive; solid', 'hazy, indistinct', 'akimbo', 'monolithic', 'hands on hips, elbows bent', 'inimical', 'Nebulous', 'to explode', 'hostile; harmful', 'state of matter', 'fulminate']
我知道列表中每个对应项的位置,因为这是混合术语和定义的列表,所以当我尝试使用此元素单击元素时
for _ in sort_order:
pos1sort = sort_order[tempVar2]
sortedList = [i for i in range(len(sort_order)) if sort_order[i] == pos1sort]
arialabel.click([sortedList[0]])
arialabel.click([sortedList[1]])
print(sortedList)
tempVar2+=1
我当然会说一个错误
AttributeError: 'list' object has no attribute 'click'
这些是列表中项目的对应位置。
[1, 4]
[2, 9]
[3, 7]
[1, 4]
[0, 5]
[6, 8]
[3, 7]
[6, 8]
[2, 9]
[10, 11]
[10, 11]
很抱歉,这个问题很长,但是我想知道如何在硒中使用click()函数来单击列表中的特定项目,这与我尝试这样做的方式类似。谢谢!
答案 0 :(得分:0)
容器只是分配给查找元素功能的另一个变量
container = driver.find_elements_by_class_name('MatchModeQuestionGridTile-content')
for _ in sort_order:
sorted1 = int(sortedList[0])
sorted2 = int(sortedList[1])
container[sorted1].click()
container[sorted2].click()