【发布时间】:2020-10-12 03:48:52
【问题描述】:
我希望我的代码从网页中选择一个随机 xpath,并在每次运行我的代码时单击它,在 Python 中使用 Selenium。
你能帮帮我吗?
谢谢。
【问题讨论】:
标签: python function selenium automation e2e
我希望我的代码从网页中选择一个随机 xpath,并在每次运行我的代码时单击它,在 Python 中使用 Selenium。
你能帮帮我吗?
谢谢。
【问题讨论】:
标签: python function selenium automation e2e
这应该可以帮助你:
from selenium import webdriver
import random
driver = webdriver.Chrome()
driver.get('url')
elements = driver.find_elements_by_xpath('//*[@id]') #Finds all elements in the page
element = random.choice(elements) #Selects a random element from the list of elements
element.click() #Clicks on the selected element
【讨论】: