Python+Selenium 下拉列表报错Message: element not interactable

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_40188140/article/details/84103350

  今天准备做一个购车页面的自动化,写到下拉列表时,运行脚本抛出了异常:selenium.common.exceptions.ElementNotVisibleException: Message: element not interactable

  如下图所示,一开始使用了select_by_index()的方法,脚本运行失败,发现是没仔细查看代码~~,此处代码不是select-option,而是table。

  脚本如下:

driver.find_element_by_xpath("//*[@id=\"style_box\"]/div[1]").click()
#Select(s).select_by_index(3)
driver.find_element_by_xpath("//*[@id=\"style_box\"]/div[2]/div[1]/table/tbody/tr[2]").click()

  很简单的两个点击,运行之后报错selenium.common.exceptions.ElementNotVisibleException: Message: element not interactable

  调试了几次,发现是没有加等待时间的缘故,加了time.sleep(3),再次调试,成功了。

  总结了一下,一方面一定要分析前端代码,另一方面当脚本报错时,尤其涉及到切换的时候,不如加个等待时间试一下吧~~

猜你喜欢

转载自blog.csdn.net/weixin_40188140/article/details/84103350