我并不是一个Selenium专家,因此我谦虚地来寻求帮助。在执行下面的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")
我想要做的是:
在 IT 技术方面,我试图实现以下目标: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格式化此内容?感谢您的帮助。谢谢。
code
。 - MacGruber