我正在尝试随机单击此page上所有未打开的选项卡(元素)。你知道吗
但不幸的是,使用这种方法似乎并没有单击所有元素。我假设出于某种原因,它不喜欢索引中的索引(或者没有正确加载所有索引)。添加while True:
可以解决这个问题,尽管我不确定如何随机分配无限量的数据。有什么想法吗?你知道吗
options = driver.find_elements_by_xpath('//*[@class="KambiBC-mod-event-group-header__event-count"]')
indexes = [index for index in range(len(options))]
shuffle(indexes)
for index in indexes:
time.sleep(1)
clickMe = wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,'(//*[@class="KambiBC-mod-event-group-header__event-count"])[%s]' % str(index + 1))))
driver.execute_script("arguments[0].scrollIntoView();", clickMe)
clickMe.click()
time.sleep(1)
添加while True:
while True:
time.sleep(0)
#clickMe = wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,'(//*[@class="KambiBC-mod-event-group-header__event-count"])[%s]' % str(index + 1))))
clickMe = wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '(//*[@class="KambiBC-mod-event-group-header__event-count"])[%s]' % str(index + 1))))
driver.execute_script("arguments[0].scrollIntoView();", clickMe)
clickMe.click()
time.sleep(0)
并非所有选项都同时出现,但它们是按组依次添加的。你知道吗
您需要等到所有选项都可用。你知道吗
请尝试以下代码:
相关问题 更多 >
编程相关推荐