2016-07-31 70 views
3

使用:与PhantomJS硒在Python修改与execute_script在硒的样式属性,但属性的值不会改变

我需要设置一个输入标签为“”,因为它被设置为一个样式属性“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脚本硒:

为什么不style属性的值由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; 
+0

** **更新:我想上的用户名输入字段改变各种属性,它的工作每一次,但密码输入字段不能改变......我知道它与显示有关:无属性,但我不知道如何补救它,如果我不能修复它。 也许我应该尝试从dom中删除该元素,然后插入没有该样式属性的副本? –

回答

1

尝试如下: -

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"); 

希望它能帮助... :)