python自动化测试-给标签的属性值进行赋值。

在某些情况下,例如我们写测试用例的时候,不想要确认这个时间控件是否可用(减少时间消耗)

我们只想要把值传送给某个属性的标签值内部

按下F12比如此处的框架是这样的:

<input style="padding-left: 0" class="time_selected" name="startTime" onblur="setMinDate(this,1,1,'13400')" type="text" onfocus="createDatepicker(this);this.blur()" readonly="readonly" date-format="yyyy-mm" max-date="" value="">

#首先获取元素

d = self.driver.find_element(By.ID,"_endTime")

#其次去除只读的属性,方便可以把值传送进去
self.driver.execute_script('arguments[0].removeAttribute("readonly")', d)
time.sleep(2)

#然后把值传送进去,使用js的方法进行传送
self.driver.execute_script("arguments[0].value = '2020-04';", a)
time.sleep(3)

原文地址:https://www.cnblogs.com/zz-1021/p/14596194.html