Chromedriver是否在动态表中执行不正常



我正试图通过在动态表上选择用户名来导航到用户页面。基本上,我首先搜索用户,然后在应用过滤器后,单击表上的链接。这应该会将我带到该用户的页面,但实际上,它会将我引导到未筛选表上的第一个用户。我甚至尝试过嵌套try/except/else语句,但结果仍然不新鲜。

预期结果:如果搜索user_x,我将出现在user_x的身份验证页面上

实际结果:如果我观察浏览器,我会看到它过滤到user_x的结果,但我最终会出现在user_a的身份验证页面上。请注意,search_results甚至在应用过滤器之后才创建。

try:
driver.find_element_by_id('name').send_keys(user['username'].title() + 'n')
except Exception as exc:
print('Error searching for {}: {}'.format(user['username'].title(), exc), file=log)
else:
print('Filtered for user: {}'.format(user['username'].title()), file=log)
try:
name_filter = wait.until(EC.visibility_of_all_elements_located((By.ID, 'name_filter')))       
except Exception as exc:
print('Error searching for {}: {}'.format(user['username'].title(), exc), file=log)
else:
print('Filter successfully applied', file=log)
try:
search_results = wait.until(EC.element_to_be_clickable((By.XPATH, "//table[@class='table table-hover']")))
except Exception as exc:
print('Error waiting for filter on {}: {}'.format(user['username'].title(), exc), file=log)
else:
search_results.click()
try:
driver.get(driver.current_url + '/#authentication')
except Exception as exc:
print('Error navigating to {}: {}'.format(driver.current_url + '/#authentication', exc), file=log)
else:
print('On authentication page for {}'.format(user['username'].title()), file=log)

事实证明,您真的不能信任HTML中的负载排序。我通过在过滤表中直接查找用户名来解决这个问题。

pause = WebDriverWait(driver, 20)
search_results = wait.until(EC.element_to_be_clickable((By.XPATH, "//*/h4[contains(text(), '{} {}')]".format(user['first_name'], user['last_name']))))

最新更新