Python 如何让selenium编辑元素

Python 如何让selenium编辑元素,python,selenium,webautomation,Python,Selenium,Webautomation,我目前正在为web自动化编写一个脚本,但我想让程序为我编辑一个元素这是我正在使用的代码示例 final=driver.find_元素(By.XPATH,“//按钮[包含(text(),'Change profile name')])” final.单击() 现在它不会点击它,因为该网站的元素设置为false,所以我希望selenium编辑并使元素为true,以便它可以点击它,这是可能的任何机会,如果有人可以解释和感谢 下面是HTML元素的外观 button class="btn btn

我目前正在为web自动化编写一个脚本,但我想让程序为我编辑一个元素这是我正在使用的代码示例

final=driver.find_元素(By.XPATH,“//按钮[包含(text(),'Change profile name')])”
final.单击()

现在它不会点击它,因为该网站的元素设置为false,所以我希望selenium编辑并使元素为true,以便它可以点击它,这是可能的任何机会,如果有人可以解释和感谢

下面是HTML元素的外观

button class="btn btn-disabled" type="submit" data-testid="ChangeNameButton" aria-describedby="changeNameFormError" aria-disabled="true" data-bi-type="button">Change profile name

因此,我不希望btn被禁用,而是希望它将其更改为启用,然后单击它,并提前感谢您提交的任何帮助:)

要更改元素的文本,请执行以下操作:

driver.execute_script("document.getElementById('theelement').innerHTML = 'changed text';");
要更改或设置元素的属性,请执行以下操作:

element =  driver.find_element_by_class_name("NAMEOFELEMENT"); 
driver.execute_script("arguments[0].setAttribute('color: blue;')", element);

您尝试单击的按钮已禁用,您可以使用JS启用它

大概是这样的:

final = driver.find_element(By.XPATH,"//button[contains(text(),'Change profile name')]")
driver.execute_script("arguments[0].setAttribute('className', 'btn-enabled');", final)

我不是在更改元素的文本,而是在编辑它。例如,当一个网站的密码是****时,常见的情况是,你将元素更改为文本,这样你就可以看到你的密码。我有没有办法告诉selenium这样做?啊,你可以做第二个选项,即:final=driver.find_元素(By.XPATH,“//按钮[包含(text(),'Change profile name')]”驱动程序。执行_脚本(“参数[0]。setAttribute('type:text;'))”,final);您必须更改文本字段而不是按钮,我放置了错误的元素downMessage:javascript错误:未能对“元素”执行“setAttribute”:需要2个参数,但只存在1个参数。我在运行以下代码时遇到此错误:final=driver.find_元素(By.XPATH,//button[contains(text(),'Change profile name'))driver.execute_脚本(“参数[0].setAttribute('className:btn-btn-enabled;')”,final)final=driver.find_元素(By.XPATH,“//按钮[contains(text(),'Change profile-name')])driver.execute_脚本(“参数[0].setAttribute('className:btn-btn-enabled;')),final)我用过这个,但我有一个error@EslamAli抱歉,我遇到语法问题…我已修复,请重试