【问题标题】:Python selenium presence_of_element_located((By.XPATH, ) need case insensitivePython selenium presence_of_element_located((By.XPATH, ) 需要不区分大小写
【发布时间】:2016-06-19 20:24:10
【问题描述】:
【问题讨论】:
标签:
python
selenium
xpath
case-sensitive
【解决方案1】:
看起来lower-case(@href) 不起作用(至少对于我在 Windows 7 上的 Firefox),fn:lower-case(@href) 也不起作用。
我求助于我在帖子中找到的translate:
'//a[contains(translate(@href, "ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz"),
"www.test.org/portal")]'
【解决方案2】:
试试这个功能。
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
def If_element_is_here_do_click(xpath_arg):
executed = 0
while (executed == 0):
try:
driver.find_element(By.XPATH, xpath_arg).click()
executed = 1
print("Clicked")
except:
print("No")
time.sleep(0.5)
然后这样调用:
If_element_is_here_do_click("/html/body/div[1]/section/main/div/div/article/div/div[2]/div/div[2]/section[1]/span[1]/button")