from selenium import webdriver driver = webdriver.Chrome()#打开一个空白浏览器 driver.get('https://www.baidu.com/') # bai度输入框的的html代码: # <input id="kw" class="s_ipt" type="text" autocomplete="off" maxlength="100" name="wd"/> # 前面的*号表示查找所有的标签元素,可以替换为标签名称input,更准确的定位元素 input_search = driver.find_element_by_xpath("//*[@id='kw']") #通过元素id查找元素 input_search = driver.find_element_by_xpath("//*[@name='wd']") #通过元素name查找元素 input_search = driver.find_element_by_xpath("//*[@class='s_ipt']") #过元素class查找元素 input_search = driver.find_element_by_xpath("//*[@maxlength='255']") #通过其他属性查找元素 input_search = driver.find_element_by_xpath("//*[@autocomplete='off']") #通过其他属性查找元素
selenium+xpath定位语法
最新推荐文章于 2025-03-24 17:33:19 发布