如何使用selenium和phantomjs激活列表项?

时间:2017-01-03 15:47:03

标签: python selenium web phantomjs

 from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.common.exceptions import NoSuchElementException
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = (
     "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/53 "
     "(KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36")
driver = webdriver.PhantomJS(desired_capabilities = dcap,service_args=['--ignore-ssl-errors=true', '--load-images=false'])
driver.get("http://www.pcna.com/leeds/pages/product.aspx?cat=PCNA&pid=7950-01_REG")
driver.implicitly_wait(5)
try:
    driver.find_elements_by_xpath("""/html/body/form/div[3]/div[5]/div/div/div/div[4]/div/div/div[5]/div/ul/li[1]""").context_click()
    driver.implicitly_wait(10)
    div_s = driver.find_elements_by_xpath("/html/body/form/div[3]/div[5]/div/div/div/div[4]/div/div/div[5]/div/div[2]/div/div/div/div[1]/div/div/div/h3")
    # div_s = driver.find_elements_by_xpath("""//*[@id="mountRoot"]/div/div/div/div[3]/div/div[2]/div[1]/table/tbody/tr""")
    size_data = ''
    for s in div_s:
        print (str(s.get_attribute("textContent")))
except NoSuchElementException:
    print ("NoSuchElementException")
Traceback (most recent call last):

  File "<ipython-input-6-ec79bd8d183a>", line 12, in <module>
    driver.find_elements_by_xpath("""/html/body/form/div[3]/div[5]/div/div/div/div[4]/div/div/div[5]/div/ul/li[1]""").context_click()

AttributeError:'list'对象没有属性'context_click'

我正在尝试从列表项中获取ajax数据。我不知道激活li的任何其他方法,因此可以废弃数据?

0 个答案:

没有答案