如何使用 Python 和 Selenium 更改元素的类属性值
我想更改班级名称,但这对我不起作用。
<div class="vcp-controls-panel vcp-playing hide">
FullXpath:
/html/body/div[1]/div/div/div/div[2]/div/div/div[1]/div[1]/div[1]/div/div[1]/div[3]/div/div[1]/div/div[1]/div[9]/div[4]
我想将 vcp-playing hide
更改为 vcp-playing show
但它不起作用
selects = driver.find_element_by_class_name("vcp-playing hide")
for select in selects:
driver.execute_script("arguments[0].setAttribute('class', 'vcp-playing show')", select)
I want to change the class name, but it doesn't work for me.
<div class="vcp-controls-panel vcp-playing hide">
FullXpath:
/html/body/div[1]/div/div/div/div[2]/div/div/div[1]/div[1]/div[1]/div/div[1]/div[3]/div/div[1]/div/div[1]/div[9]/div[4]
I want to change vcp-playing hide
to vcp-playing show
but it doesn't work
selects = driver.find_element_by_class_name("vcp-playing hide")
for select in selects:
driver.execute_script("arguments[0].setAttribute('class', 'vcp-playing show')", select)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于现有元素已经设置了 classname 属性:
您可以通过
removeAttribute( )
使用setAttribute()
如下:注意:您必须添加以下内容进口:
As the existing element already have the classname attribute set:
You can remove the existing attributes through
removeAttribute()
set the new attributes usingsetAttribute()
as follows:Note : You have to add the following imports :
完全用 javascript 来做怎么样?
how about do it completely in javascript