使用Selenium Web驱动程序访问侧面导航栏元素时出现问题

时间:2019-06-10 18:21:54

标签: python html selenium-webdriver selenium-chromedriver

我正在尝试使用用于chrome的硒Web驱动程序与侧面导航栏元素进行交互,但始终会出现错误,并且不确定如何使用XPATH正确访问标签元素。我添加了几个Jpegs,它们显示了在chrome中使用inspect元素时存在的HTML代码。这些是我enter image description here尝试访问的元素。

我曾尝试通过XPATH使用WebDriverWait进行访问

import urllib2, os, zipfile, re, timeit, logging, getpass, datetime, arcpy
#from bs4 import BeautifulSoup
from selenium import webdriver
#import csv, zipfile
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException

start = timeit.default_timer()

username = getpass.getuser()
initials = getpass.getuser()[:2].upper()

chrome_options = Options()
chrome_options.add_argument("--headless")
output_dir = r'C:\GIS-Long\REQUESTS\PWT\WasteIndustries_MapApplication_pickup_days\test_output'
recollect_url = r"https://manage.recollect.net/admin/area/Apex/waste/metrics/calendar"
driver = webdriver.Chrome("C:\Users\Jlong\Downloads\chromedriver_win32\chromedriver.exe",chrome_options=chrome_options)
driver.get(recollect_url)

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH,
     "//button[@class='navbar-toggle menu-toggler pull-left'][type='button']//span[@class='sr-only']"))).click()

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH,
                                                                "//a[@data-sidebar='address-dropdown']//span["
                                                                "@class='menu-text'][contains(.,"
                                                            "'Addresses')]"))).click()

enter image description here

我希望代码能够运行而没有任何类型的错误,并且能够访问导航栏中的标记元素以进行进一步处理。我不断收到TimeoutException

0 个答案:

没有答案