Selenium webdriver python从websi查找动态文本

2024-09-30 18:29:18 发布

您现在位置:Python中文网/ 问答频道 /正文

网站

Website

myList = ['Artik']

如何检查我的列表内容是否在上面的网站可见?你知道吗

<span class="ipo-TeamStack_TeamWrapper">Artik<span>

这个网站中的“Artik”元素。你知道吗

我的目标是单击包含“Artik”的元素,然后执行一些操作。你知道吗


Tags: 元素内容目标列表网站classspanmylist
2条回答
driver.find_elements_by_xpath("//*[contains(text(), 'Artik')]")

此返回WebElement列表包含“Artik”。
参数(如'Artik')区分大小写。你知道吗


如果你确信“阿蒂克”只是其中一个

driver.find_element_by_xpath("//*[contains(text(), 'Artik')]").click()

这将找到带有“Artik”的WebElement并单击。你知道吗

这就是如何通过selenium中的xpath查找元素。我在这里使用Firefox,但你也可以使用Chrome。你知道吗

from selenium import webdriver

myList = ['Artik']
driver = webdriver.Firefox() # or .Chrome()
driver.get('www.theWebsite.com')

current = driver.find_element_by_xpath('//span[@class="ipo-TeamStack_TeamWrapper"]').text
if current in myList:
    print('YAY')

driver.quit()

相关问题 更多 >