【问题标题】:Cannot run the code and print out the result, using xpath and webdriver to click the pulldown menu无法运行代码并打印出结果,使用xpath和webdriver点击下拉菜单
【发布时间】:2020-09-26 00:44:29
【问题描述】:

无法运行代码并打印结果,使用xpath和webdriver通过以下代码点击下拉菜单

 from selenium import webdriver
 from selenium.webdriver.common.by import By
 from selenium.webdriver.support.ui import WebDriverWait
 from selenium.webdriver.support import expected_conditions as EC

 driver = webdriver.Firefox()
 driver.get('URL')
 driver.maximize_window()
 wait = WebDriverWait(driver,40)
 wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,'div.combobox-input-wrap a[data-value="rbAll"]'))).click()
 wait.until(EC.element_to_be_clickable((By.XPATH,'//div[@class="droplist-item"]/a[contains(.,"Headline Category")]'))).click()
 wait.until(EC.element_to_be_clickable((By.XPATH,'//div[@id="rbAfter2006"]//div[@class="combobox-input-wrap"]/a[contains(.,"ALL")]'))).click()
 wait.until(EC.element_to_be_clickable((By.XPATH,'//div[@class="droplist-group"]//ul[@class="droplist-items"]//li/a[contains(.,"Announcements and Notices")]'))).click()
 ele=wait.until(EC.presence_of_element_located((By.XPATH,'//div[@class="droplist-group droplist-submenu level2"]//ul//li/a[contains(.,"New Listings (Listed Issuers/New Applicants)")]')))
 ele.location_once_scrolled_into_view
 ele.click()
 ele2=wait.until(EC.presence_of_element_located((By.XPATH,'//div[@class="droplist-group droplist-submenu level3"]//ul//li/a[contains(.,"Allotment Results")]')))
 ele2.location_once_scrolled_into_view
 ele2.click()

 html = driver.page_source
 print html

运行时的错误日志如下所示。

File "run.py", line 6, in <module>
   driver = webdriver.Firefox()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 167, in __init__
keep_alive=True)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 156, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 251, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 320, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 1

【问题讨论】:

    标签: selenium-webdriver xpath


    【解决方案1】:

    您应该在括号内打印值,即

    html = driver.page_source
    print(html)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-20
      • 2012-09-05
      • 1970-01-01
      相关资源
      最近更新 更多