【问题标题】:Python Selenium Random xpath clickPython Selenium 随机 xpath 点击
【发布时间】:2020-10-12 03:48:52
【问题描述】:

我希望我的代码从网页中选择一个随机 xpath,并在每次运行我的代码时单击它,在 Python 中使用 Selenium。

你能帮帮我吗?

谢谢。

【问题讨论】:

    标签: python function selenium automation e2e


    【解决方案1】:

    这应该可以帮助你:

    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
    

    【讨论】:

    • YW!一个来自我身边的卑微请求。你能接受我的答案作为最佳答案吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-24
    • 1970-01-01
    • 1970-01-01
    • 2013-06-03
    • 2021-06-09
    • 2013-12-15
    • 1970-01-01
    相关资源
    最近更新 更多