selenium的各种使用

 

selenium加载用户配置:

https://stackoverflow.com/questions/50635087/how-to-open-a-chrome-profile-through-user-data-dir-argument-of-selenium/50637211#50637211

 

<div>My Button</div>

按照 Text文本 来选择 对应的控件

 

选择的格式为:

driver.find_elements_by_xpath("//*[contains(text(), 'My Button')]")

或者:

my_element = driver.find_element_by_xpath("//div[text()='My Button']")

参考链接:

https://stackoverflow.com/questions/12323403/how-do-i-find-an-element-that-contains-specific-text-in-selenium-webdriver-pyth

 

当运行时候报错,报错信息为:

Message: element not interactable

解决方案为:

不使用自带的click() 而使用脚本

element = driver.find_element_by_xpath("(//a[contains(@href, '')])[20]")
driver.execute_script("arguments[0].click();", element)

参考链接:https://stackoverflow.com/questions/56194094/how-to-fix-this-issue-element-not-interactable-selenium-python

 

定位元素,以下也不失为一个好方法:

save_items = []

for item in driver.find_elements_by_tag_name("input"):
    # Get class
    item_class = item.get_attribute("class")

    # Get name:
    item_name = item.get_attribute("name")

    # And so on...


    # Check for a match
    if item_class == "W_input" and item_name == "14235541231062":
        # Do your operation (or add to a list)
        save_items.append(item)
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值