【问题标题】:Cannot find a link找不到链接
【发布时间】:2018-04-27 20:00:28
【问题描述】:

我正在尝试点击网页上的标签(区域监管):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.7 selenium-webdriver xpath web-scraping nosuchelementexception


    【解决方案1】:

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

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-12
    • 2018-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多