动态ID-如何在Python中使用selenium单击动态按钮

动态ID-如何在Python中使用selenium单击动态按钮,python,selenium,selenium-webdriver,Python,Selenium,Selenium Webdriver,这个按钮是复制的;复制上框中的文件共享链接。以下是我的尝试: getLink = driver.find_element_by_xpath("""//*[starts-with(@id, "ic0") and contains(@id, "544")]""").click() 还是不行。类是“#c0-5443772”,但它是动态的 谢谢你们的帮助,伙计们 页面的HTML代码: 页面截图: 要单击

这个按钮是复制的;复制上框中的文件共享链接。以下是我的尝试:

getLink = driver.find_element_by_xpath("""//*[starts-with(@id, "ic0") and contains(@id, "544")]""").click()
还是不行。类是“#c0-5443772”,但它是动态的

谢谢你们的帮助,伙计们

页面的HTML代码: 页面截图:


要单击可用于下载链接的复制按钮,您可以使用以下xpath:

//h2[text()='Download Link']//following-sibling::button
//h2[text()='Embed code']//following-sibling::button
类似地,您可以使用下面的Xpath作为论坛的链接

//h2[text()='Link for forums']//following-sibling::button
对于最后一个和第四个按钮,您可以使用以下xpath:

//h2[text()='Download Link']//following-sibling::button
//h2[text()='Embed code']//following-sibling::button
对于粘贴,可以使用pyperclip

确保使用pip
pip安装pyperclip

paste_string= pc.paste();
  
print(paste_string)
更新1:

from time import sleep
import tkinter as tk
import clipboard as clipboard
import pyautogui as pyautogui
import pyperclip as pyperclip
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
import pandas as pd

driver = webdriver.Chrome("C:\\Users\\Desktop\\Selenium+Python\\chromedriver.exe")
driver.maximize_window()
wait = WebDriverWait(driver, 100)
driver.get("https://www.streamsb.com/login.html")

#   Login

user = driver.find_element_by_css_selector("#login > div > form > div:nth-child(3) > div > input[type=text]").send_keys("Enter here")
password = driver.find_element_by_css_selector("#login > div > form > div:nth-child(4) > div > input[type=password]").send_keys("Enter here")
enter = driver.find_element_by_css_selector("#login > div > form > div:nth-child(7) > div > input[type=submit]").click()
#   Navigation and upload
driver.find_element_by_css_selector("#mAcct > div.mnu > div > ul > li:nth-child(1) > a").click()
driver.find_element_by_css_selector("#mainmenu > ul > li:nth-child(2) > a").click()
driver.find_element_by_css_selector("#filepc").send_keys("C:\\Selenium+Python\\file_example_MP4_480_1_5MG.mp4")

uploadButton = driver.find_element_by_class_name("upload-form-button").click()

copy_button = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'button.btndiv')))

print("before clicking copy button.")
copy_button.click()

text = clipboard.paste() # text will have the content of clipboard
print(text)

有四个复制Html代码用于4个选项卡,每个选项卡具有不同的id,但具有相同的类。因此,您可以使用XPath之类的东西

"//h2[contains(.,'"+tabName+"')]//following-sibling::button"
这里tab Name是作为tab Name值传递的变量 例如


//h2[包含(,'Download Link')]//以下兄弟姐妹::button

能否请您共享button或您的URL的html代码为了帮助您查看该页面的html,最好在帖子中更新指向该页面的链接及其自身屏幕截图和源代码@单击哪个按钮?复制按钮或上面框中复制链接的任何按钮@cruisepandeySo,我已经这样做了:getLink=
driver。通过xpath(“h2[text()='Embed code']//following sibling::button”)查找元素。单击()
如果单击了复制按钮,然后,从逻辑上讲,链接将存储在剪贴板中,但它不存储链接。您是如何确定它不存储链接的?因为我粘贴了链接,而我复制的内容仍在那里。您可以使用pyperclip粘贴值,更新我的答案。看看,当我运行它时,什么都没有出现。你能运行我的代码吗。不工作。剪贴板仍然没有链接。剪贴板在运行时有链接。您需要编写代码以粘贴到运行时中所需的位置,否则按钮功能将无法正常工作,对此我毫不怀疑。但是您不应该因为没有识别复制按钮而出错。我尝试过这样做:
getLink=driver。通过xpath(“h2[text()='Download Link']//following sibling::button”)查找元素。单击()打印(pyperclip.paste(getLink))
运行它时没有显示任何内容。