Python - 复制元素

Python - Copy element

我一直在练习 Python 观看教程和阅读书籍,但我正在努力使用 copy 功能。我正在尝试复制填充到 元素框 中的 ID,因此我找到该元素并尝试复制它但不起作用。 :(

alert = driver.switch_to_alert()
alert.accept()
driver.find_element_by_xpath('/html/body/form[2]/table[1]/tbody/tr[1]/td[3]').copy2.copy()

我收到这个错误 -

AttributeError: 'WebElement' object has no attribute 'copy2'

我想让我的程序复制 'Search ID' 框中的数字。

A WebElement instance has no copy2 attribute in Python selenium bindings. – alecxe 1 hour ago

感谢 Alexcxe 的回答

分辨率: 本来我想做的是复制元素字段中的文本并保存以备后用。我现在为解决该问题所做的是保存文本。

for element in driver.find_elements_by_xpath('/html/body/form[2]/table[1]/tbody/tr[1]/td[3]'): print ("This is the shopID") print (element.text) 

现在我在 运行 程序

时保存了它