我通过提供延迟(time.sleep()
)编写了如下代码,但我希望通过调用try
例外功能来修改代码。所以要修改下面的代码。
def min_power(self):
power_min_list = ["Carrier", "@#$%", "-1", "101", "22"]
time.sleep(6)
for i in range(len(power_min_list)):
if i == 0:
pencil()
power_min = web.find_element_by_id("powmin")
power_min.clear()
power_min.send_keys(power_min_list[i])
submit()
time.sleep(3)
var1 = web.find_element_by_xpath("//div[@id='grp_powmin']//span[contains(text(),'Number must be between 0 and 100.')]").text
var2 = "Number must be between 0 and 100."
if var1 == var2:
pass
else:
print ("Failed - invalid data written successfully")
if i == 3:
power_min = web.find_element_by_id("powmin")
power_min.clear()
power_min.send_keys(power_min_list[4])
submit()
time.sleep(6)
var = power_min_list[4]
var3 = web.find_element_by_xpath("//*[@id='modulation_table']/tbody/tr[1]/td[3]").text
if var == var3:
pass
else:
print ("Failed - Power Min wrong Data is written successfully")
答案 0 :(得分:0)