【发布时间】:2013-10-08 18:00:01
【问题描述】:
我绝不是硒专家,因此我谦虚地来到这里寻求帮助。在执行下面的 python 脚本后,我想如果它在两次打印之间失败,我可以简单地查看日志并查看最后一次打印的位置。不幸的是,脚本会一直运行到最后并打印所有内容,无论它是否成功。这是我所拥有的:
print("Attempting, map zoom 4x.")
driver.find_element_by_xpath("//*[@class=\"leaflet-control-zoom-in\"]").click()
driver.find_element_by_xpath("//*[@class=\"leaflet-control-zoom-in\"]").click()
driver.find_element_by_xpath("//*[@class=\"leaflet-control-zoom-in\"]").click()
driver.find_element_by_xpath("//*[@class=\"leaflet-control-zoom-in\"]").click()
print("Zoom in 4x. Successful")
我想要做的是:
print("Attempting, map zoom 4x.")
if driver.find_element_by_xpath ...... exists,
then
driver.find_element_by_xpath("//*[@class=\"leaflet-control-zoom-in\"]").click()
driver.find_element_by_xpath("//*[@class=\"leaflet-control-zoom-in\"]").click()
driver.find_element_by_xpath("//*[@class=\"leaflet-control-zoom-in\"]").click()
driver.find_element_by_xpath("//*[@class=\"leaflet-control-zoom-in\"]").click()
print("Zoom in 4x. Successful")
else
print("Element does not exist, it failed.")
如何为 python/selenium 设置格式?任何帮助表示赞赏。谢谢。
【问题讨论】: