小编Nor*_*yan的帖子

使用带有 Selenium 的 webdriver 访问网站被拒绝

即使使用“webdriver Chrome”打开网站,我也遇到问题。只尝试打开网站,结果显示“访问被拒绝”信息,但不知道为什么。下面是我的代码:

from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options

import time

class PriceCheckPhoenix:
    def __init__(self):
        self.url_login = "https://www.phoenixcontact.com/online/portal/pl?1dmy&urile=wcm%3apath%3a/plpl/web/home"

        self.create_session()

    def create_session(self):
    # Run browser with webdriver

        driver = webdriver.Chrome(executable_path="D:/chromedriver_v84.exe")
        driver.get(self.url_login)

        time.sleep(2)

        # Find link to sub-website with login
        link = driver.find_element_by_xpath('//*[@id="pxc-funcnav"]/div[3]/ul/li[1]/a').get_attribute("href")
    
        driver.get(link)

        time.sleep(100)
Run Code Online (Sandbox Code Playgroud)

代码说明:

#1 我创建浏览器 chrome 会话

#2 从 self.url_login 加载第一个网站

#3 已加载

#4 我需要找到网站上活动文本后面的链接才能登录

#5 我找到它并尝试打开它,但获得链接后的响应是:

Access Denied
You …
Run Code Online (Sandbox Code Playgroud)

python selenium selenium-webdriver chrome-web-driver

3
推荐指数
1
解决办法
1万
查看次数

Cypress:当“应该”断言失败时如何捕获错误

should当断言失败时我需要捕获错误。想象一下 .should('not.exist') 的第一个断言失败了(元素仍然可见)

我需要的示例(但这不适用于 Cypress 和 JS):

   this.containsInIframe('tr', assetName)
  .find('div.loader', { timeout: 100000 })
  .should('not.exist')
  .catch((error) => {
    this.reloadPage();
    this.containsInIframe('tr', assetName)
      .find('div.loader', { timeout: 100000 })
      .should('not.exist');
  });
Run Code Online (Sandbox Code Playgroud)

使用Cypress和JS如何处理这种情况?谁能提出解决这个问题的方法?

如何捕获 cypress 'should' 断言抛出的错误?

javascript cypress

-2
推荐指数
1
解决办法
158
查看次数