首页 > 解决方案 > 找不到链接

问题描述

我正在尝试单击网页上的选项卡(区域监管):https ://www5.fdic.gov/idasp/advSearchLanding.asp

但是,它不识别该命令。在这里,我附上了代码。

import urllib2
import urllib
from bs4 import BeautifulSoup
import subprocess
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys
browser = webdriver.Chrome("/usr/local/bin/chromedriver")
import time



s1_url = 'https://www5.fdic.gov/idasp/advSearchLanding.asp'
browser.get(s1_url)

问题:选择监管区域选项卡,但没有单击它。

browser.find_element_by_xpath('//[@id="Banks_Regulatory_Tab"]/a').click()

有一个例外:

NoSuchElementException:消息:没有这样的元素:无法找到元素:{"method":"xpath","selector":"//*[@id="Banks_Regulatory_Tab"]/a"}

标签: python-2.7selenium-webdriverxpathweb-scrapingnosuchelementexception

解决方案


位于 iframe 内的必需元素。为了能够处理它,您需要切换到该 iframe:

browser.switch_to.frame("content")
browser.find_element_by_link_text("Regulatory Regional").click()

推荐阅读