无法找到元素:硒

问题描述 投票:1回答:1

enter image description here

我想通过单击选择更多信息链接。我已经尝试了所有可能的方法,但是每次错误NoSuchElementException:no这种元素:无法找到元素:{“ method”:“ xpath”,“ selector”弹出。

起初,我想也许是因为我没有正确更改选项卡,所以才显示此错误。但是,即使使用window_handles后,仍然无法在此页面上找到任何元素。

帮助

self.driver.window_handles
        base = self.driver.window_handles[0]        
        child = self.driver.window_handles[1]

        window_set = {self.driver.window_handles[0], self.driver.window_handles[1]}

for x in window_set:
        if(base != x):
            self.driver.switch_to.window(x)
            self.driver.find_element_by_id("mc-lnk-moreInfo").click() 
selenium selenium-webdriver automation selenium-chromedriver nosuchelementexception
1个回答
0
投票

尝试wait for the element,然后单击它

替换

self.driver.find_element_by_id("mc-lnk-moreInfo").click()

有下列内容

  self.more_info = WebDriverWait(self.driver, 30).until(
        ec.visibility_of_element_located((By.ID, "//a[@id='mc-lnk-moreInfo']")))
    ActionChains(self.driver).move_to_element(self.more_info).click().perform()

在您的导入内容上添加以下内容

from selenium.webdriver import ActionChains
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
© www.soinside.com 2019 - 2024. All rights reserved.