博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python xpath selenium
阅读量:6894 次
发布时间:2019-06-27

本文共 2509 字,大约阅读时间需要 8 分钟。

xpath 或运算

model_node_list = self.driver.find_elements_by_xpath(                '//*[@id="cc"]/div[6]/div[1]/ul/li/a[1]|//*[@id="cc"]/div[6]/div[2]/ul/li/a[1]')

获取父节点

t=node.find_element_by_xpath('..')

模拟hover事件

from selenium import webdriverfrom selenium.webdriver import ActionChainsfrom mysqlHelper import MysqlHeplerclass Proccessor:    def __init__(self):        self.driver = webdriver.Chrome("C:\\software\\chromedriver_win32\\chromedriver.exe")        self.cnt = True        pass    def start(self):        self.driver.maximize_window()        self.driver.get("http://www.mtmchina.cn")        node = self.driver.find_element('//*[@id="brands"]')        model_hover = ActionChains(self.driver).move_to_element(node)        model_hover.perform()proccessor = Proccessor()proccessor.start()

根据css属性选择节点

model_node_list = self.driver.find_elements_by_xpath('//*[@id="productfinder"]/ul/li[contains(@style,"display: block")]')

获取某一个元素下面的子元素

self.driver.maximize_window()        self.driver.get("http://www.mtmchina.cn")        li_node_list = self.driver.find_elements_by_xpath('//*[@id="productfinder"]/ul[2]/li')        link_num = 1        for li in li_node_list:        #获取当前元素下面的a元素            a = li.find_element_by_css_selector('a')            href = a.get_attribute('href')            if href == "http://www.mtmchina.cn/#":                continue            self.url_list.append(href)            print(li.text, href)            link_num += 1        print("总连接", link_num)

获取节点的class

cl = li.get_attribute("class")

设置节点Id

self.driver.execute_script('arguments[0].setAttribute("id","nurmemet_img_id");', img)
sel_items = self.driver.find_elements_by_xpath(                    '//*[@id="content_container"]/div[1]/a[contains(@class, "slider_image_selected")]')
info_side=self.driver.find_element_by_class_name("information-side")#information-side 下面的节点h1h1=info_side.find_element_by_css_selector("h1")# information-side下面的节点h2h2=info_side.find_element_by_css_selector("h2")#information-side 下面的节点clearfixclearfix=info_side.find_element_by_css_selector(".clearfix");#information-side 下面的节点product-feautured-specificationul=info_side.find_element_by_css_selector(".product-feautured-specification");

等待元素的出现

from selenium.webdriver.common.by import Byfrom selenium.webdriver.support.wait import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECwait = WebDriverWait(self.driver, 40)            element = wait.until(EC.element_to_be_clickable((By.CLASS_NAME, 'information-side')))

转载地址:http://gbudl.baihongyu.com/

你可能感兴趣的文章
众美集团携手万科物业 树立济南人居高标准
查看>>
形象比你的头衔更重要 看过悦嘉丽形象锻造营你就知道为什么
查看>>
Oracle 数据库导出数据泵(EXPDP)文件存放的位置
查看>>
组播中如何把广播流量转为组播流量
查看>>
ZooKeeper服务命令
查看>>
利用虚拟化实现应用发布与网络隔离
查看>>
redis两种调用方式实例
查看>>
我的友情链接
查看>>
oracle分区表
查看>>
(转载)centos6.5下安装mysql
查看>>
宽带用户防范“***”***十大招式
查看>>
PHP5.4第一天—基本语法
查看>>
thinkphp 5.0 index.php被替换成首页内容,被注入恶意代码
查看>>
Linux定制自动安装
查看>>
尝试搭建一个日志服务器
查看>>
android开源工程--开篇
查看>>
CentOS6上mongodb连接数无法突破1000的解决办法
查看>>
linux 修改 计算 名称 root@localhost
查看>>
oracle计算日期只差得出季度
查看>>
linux 下查找大于100M的文件
查看>>