使用:Selenium与Python 中的PhantomJS
我需要将输入标记的样式属性设置为",因为它被设置为"display:None",这会阻止我在Selenium中用send_keys填充输入。
我正在使用execute_script来实现这一点。execute_script运行,但style属性保持不变。为什么PhantomJS不更改样式属性?
我要删除的带有样式属性的HTML:
<input type="password" size="10" id="navbar_password" name="vb_login_password" tabindex="102" class="textbox" style="display: none;">
Python Selenium脚本:
execute_script为什么不更改样式属性的值?
password = driver.find_element_by_name("vb_login_password")
driver.execute_script("arguments[0]['style'] = arguments[1]", password, '')
print(password.get_attribute("style"))
//display:none;
按以下方式尝试:-
password = driver.find_element_by_name("vb_login_password")
password = driver.execute_script("arguments[0].style.display = 'block'; return arguments[0];", password)
print(password.value_of_css_property("display"))
#now you can set value using send_keys
password.send_keys("your value");
希望它能帮助…:)