无法找到元素:// * [@ id =“ US-6”]和xpath

我遇到以下问题。

每次尝试找到此尺寸时,我都会尝试选择下一个尺寸:

| error,selenium.common.exceptions.NoSuchElementException: Message: Unable to
locate element: // * [@ id = "US-6"] |

我想避免脚本结尾 然后尝试点击

// * [@ id = "US -7 "]

无需中断脚本。

我不知道是否有可能。我真的需要帮助。

lanhu091 回答:无法找到元素:// * [@ id =“ US-6”]和xpath

您可以执行以下操作。

from selenium.common.exceptions import NoSuchElementException

try:
    driver.find_element_by_xpath('//*[@id = "US-6"]') 
except NoSuchElementException:
    driver.find_element_by_xpath('// * [@ id = "US -7 "]') 
本文链接:https://www.f2er.com/3155713.html

大家都在问