代码:
# -*- coding: utf-8 -*-
from selenium import webdriver
from mon.by import By
from mon.keys import Keys
from selenium.webdriver.support.ui import Select
from mon.exceptions import NoSuchElementException
from mon.exceptions import NoAlertPresentException
import unittest, time, re
class KeywordsAnalyse(unittest.TestCase):
driver=webdriver.Chrome("E:\chromedriver_win32\chromedriver.exe")
driver.get("https://。。。。。。/oldriver/login")
driver.find_element_by_id("username").clear()
driver.find_element_by_id("username").send_keys("")
driver.find_element_by_id("password").clear()
driver.find_element_by_id("password").send_keys("000000")
driver.find_element_by_xpath(".//*[@id='loginForm']/input").click()
driver.find_element_by_xpath(".//*[@id='side-menu']/li[4]/a").click()
driver.find_element_by_xpath(".//*[@id='keywords']").send_keys("fidget spinner")
select=Select(driver.find_element_by_id("category"))
all_options=driver.find_element_by_id("category")
for option in all_options:
print("")
driver.find_element_by_id("btnSubmit").click()
报道错误:TypeError: 'WebElement' object is not iterable 修改:
all_options=driver.find_element_by_id("category")改为
all_options=driver.find_elements_by_id("category")