|
不对啊,我用了一selenium3.8.0,然后代码是这个样子的- import time
- from selenium import webdriver
- from selenium.webdriver import ActionChains
- driver = webdriver.Chrome()
- driver.get('https://www.douban.com/')
- input_tag = driver.find_element_by_xpath('/html/body/div[1]/div[2]/div[3]/form/span[1]/input')
- button_tag = driver.find_element_by_xpath('/html/body/div[1]/div[2]/div[3]/form/span[2]/input')
- act = ActionChains(driver)
- act.move_to_element(input_tag)
- act.click(input_tag)
- str = '觉醒年代'
- act.send_keys_to_element(input_tag, str).perform()
- time.sleep(2)
- act = ActionChains(driver)
- act.move_to_element(button_tag)
- act.click(button_tag).perform()
- time.sleep(1)
- driver.quit()
复制代码
这个样子是可以的,但是如果代码是下面这样的话
- import time
- from selenium import webdriver
- from selenium.webdriver import ActionChains
- driver = webdriver.Chrome()
- driver.get('https://www.douban.com/')
- # 定位
- input_tag = driver.find_element_by_xpath('/html/body/div[1]/div[2]/div[3]/form/span[1]/input')
- button_tag = driver.find_element_by_xpath('/html/body/div[1]/div[2]/div[3]/form/span[2]/input')
- act = ActionChains(driver)
- act.move_to_element(input_tag)
- act.click(input_tag)
- str = '觉醒年代'
- act.send_keys_to_element(input_tag, str).perform()
- time.sleep(2)
- act.move_to_element(button_tag)
- act.click(button_tag).perform()
- time.sleep(1)
- act.perform()
- driver.quit()
复制代码
那么我搜索的就是“觉醒年代觉醒”了
如果我把上面的act.click(button_tag).perform()改成act.click(),那么搜索的就是“觉醒年代觉”了,这是什么啊?呜呜呜 |
|