Selenium Element ClickInterceptedException错误

发布于 2025-02-10 13:02:00 字数 1009 浏览 4 评论 0原文

我正在研究这个 weblote 基本上,我想从news部分中捕获两个最新新闻,该部分位于桌子下方,并在某些JSON中存储该新闻,并在可能的情况下收集图片,但我无法访问新闻部分,因为它总是会增加错误说

selenium.common.exceptions.elementClickInterceptedException:消息:element< aid =“ ctl00_contentplaceholder1_companydetail1_lnknknewstab” href =“ href =”#divnews“> gt; is not clickable at point (307,786) because another element

这是我尝试过的代码的某些部分

driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
stocks_data = ["AKPL","NICA"]

for stock_data in stocks_data:
     self.driver.get(f'https://merolagani.com/CompanyDetail.aspx?symbol= 
      {stock_data.lower()}')
      self.driver.find_element_by_xpath("//li[@id='navNews']"
                              "//a[@id='ctl00_ContentPlaceHolder1_CompanyDetail1_lnkNewsTab']").click()

I am working on this website
Basically I want to capture 2 latest news from News section that is below the table and store that news in some json and collect picture if possible but I am not able to go to the news section as It always raise error saying

selenium.common.exceptions.ElementClickInterceptedException: Message: Element <a id="ctl00_ContentPlaceHolder1_CompanyDetail1_lnkNewsTab" href="#divNews"> is not clickable at point (307,786) because another element <iframe id="webpush-onsite" name="webpush-onsite"> obscures it

here is some part of code I tried tough

driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
stocks_data = ["AKPL","NICA"]

for stock_data in stocks_data:
     self.driver.get(f'https://merolagani.com/CompanyDetail.aspx?symbol= 
      {stock_data.lower()}')
      self.driver.find_element_by_xpath("//li[@id='navNews']"
                              "//a[@id='ctl00_ContentPlaceHolder1_CompanyDetail1_lnkNewsTab']").click()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽你眉间 2025-02-17 13:02:00

如果您真的需要单击它,无论普通用户都无法解决,因为正如错误所说,它的顶部有一个iframe ...

尝试以下内容:

  1. 将窗口大小设置为1920x1080左右,也许是元素重叠,因为Selenium会话中的屏幕太小

If you really need to click it regardless a normal user won't be able because as the error says, there's an IFrame on top of it...

Try the following:

  1. Set the window size to 1920x1080 or so, maybe the elements overlap because the screen on Selenium's session is too small ????‍♂️

  2. Worst case scenario, inject some Javascript code to do it forcefully:

self.driver.execute_script("document.getElementById('ctl00_ContentPlaceHolder1_CompanyDetail1_lnkNewsTab').click()")
  1. Click on exact coordinate (x,y) if you know it ofcs.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文