目录
# 1. 概述
# 2. 实操
# 3. 完整代码
# 4. 实际效果
# 1. 概述
找到节点 - .send_keys - 获取下拉表 - 选取想要的
# 2. 实操
最重要的一个技巧是 pause,即把页面暂停,再获取我们的列表框
此时显示页面已经暂停,再回到 Elements 界面,选取需要的列表元素
?最后在获取的列表框里,用循环选取我们需要的关键词
listElements = driver.find_elements(By.XPATH,'//div[@id="emailmore_menu"]/ul/li')
print(len(listElements))
for ele in listElements:
if '163' in ele.text:
print("Record found:",ele.text)
ele.click()
break
# 3. 完整代码
# -*- coding = utf-8 -*-
# @Time : 2021/10/18 10:19
# @Author : LIUYU
# @File : HadleAutoSuggestions.py
# @Software : PyCharm
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
s = Service("D:\Software\webdrivers\chromedriver.exe")
driver = webdriver.Chrome(service=s)
driver.maximize_window()
driver.get("https://www.52pojie.cn/member.php?mod=LSG_52register")
driver.implicitly_wait(20)
driver.find_element(By.XPATH,'//button/span[text()="同意"]').click()
driver.find_element(By.ID,'PJ52email').send_keys("liuyu123")
listElements = driver.find_elements(By.XPATH,'//div[@id="emailmore_menu"]/ul/li')
print(len(listElements))
for ele in listElements:
if '163' in ele.text:
print("Record found:",ele.text)
ele.click()
break
# 4. 实际效果
|