xyh2695368537 发表于 2022-10-3 16:51:46

关于selenium的问题

本帖最后由 xyh2695368537 于 2022-10-3 17:28 编辑



图中的城市,除了用xpath进行定位选择,还能怎么找到这个元素

wp231957 发表于 2022-10-3 17:20:58

你这是想定位谁

xyh2695368537 发表于 2022-10-3 17:26:03

wp231957 发表于 2022-10-3 17:20
你这是想定位谁

想要选择城市,这种能用键盘输入吗?

wp231957 发表于 2022-10-3 17:59:46

xyh2695368537 发表于 2022-10-3 17:26
想要选择城市,这种能用键盘输入吗?

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select as select
import time

drv=webdriver.Chrome(r"d:\python310\chromedriver.exe")
drv.get("http://ad.jxzyz.cn/vol/index.php/Home/Index/zc.html")


js = "document.getElementById('birthday').removeAttribute('readonly')"
drv.execute_script(js)
birthday = drv.find_element(By.ID,"birthday")
birthday.send_keys('2022-10-03')
s1=select(drv.find_element(By.XPATH,"//*[@id='form1']/dl/dd/table/tbody/tr/td/select"))
s1.select_by_visible_text("江西省")
time.sleep(1)
s2=select(drv.find_element(By.ID,"city"))
s2.select_by_visible_text("抚州市")
time.sleep(1)    #如果网路延时大,这里可以加时
s3=select(drv.find_element(By.ID,"area"))
s3.select_by_visible_text("广昌县")
time.sleep(1)
s4=select(drv.find_element(By.ID,"town"))
s4.select_by_visible_text("长桥乡")

xyh2695368537 发表于 2022-10-3 18:17:21

wp231957 发表于 2022-10-3 17:59


成功了!!感谢!!!
{:10_266:}
页: [1]
查看完整版本: 关于selenium的问题