小编Deb*_*anB的帖子

如何修复 AttributeError:“NoneType”对象没有属性“click”

如何解决错误AttributeError: \'NoneType\' object has no attribute \'click\'?它的失败在于self.home.get_you_button().click(). 当我没有创建页面对象类时,它\xe2\x80\x99s 工作正常...它单击“You”按钮,没有任何错误,但通过使用 POM,它\xe2\x80\x99s 失败。网址是https://huew.co/

\n\n

代码试验:

\n\n
from selenium.webdriver.support import expected_conditions\nfrom selenium.webdriver.support.wait import WebDriverWait\n\nclass HomePage():\n\n    def __init__(self,driver):\n        self.driver = driver\n\n    def wait_for_home_page_to_load(self):\n        wait =WebDriverWait(self.driver,30)\n        wait.until(expected_conditions.visibility_of(self.driver.find_element_by_tag_name(\'html\')))\n\n    def get_you_button(self):\n\n        try:\n            element = self.driver.find_element_by_xpath("//div[@class=\'desktop-public-header\']/a[@ng-controller=\'UserNavigationInteractionCtrl\'][6]")\n\n        except:\n            return None\n
Run Code Online (Sandbox Code Playgroud)\n

python selenium python-3.x selenium-webdriver webdriverwait

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

Selenium 和非无头浏览器不断要求验证码

我遇到了一个问题,我们的一个网站一直在云中的浏览器中以无头模式要求验证码,所以我将其切换为非无头模式,这样我就可以自己输入验证码,我想下次它会工作,也许是因为一些 cookie 已经被存储了,但即使我输入了几次验证码,它也没有存储。

另外值得一提的是,它在任何模式下都可以在本地运行良好,并且对于非自动化版本,它在云中也运行良好,但是一旦我在任何模式下使用 Selenium 运行它,它就会不断要求验证码。非常感谢任何可能发生的事情和解决方案的想法

selenium captcha webdriver selenium-webdriver webdriver-w3c-spec

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

selenium 将两个 xpath 测试合二为一

我尝试结合检查两种情况:

如果启动检查失败,我们会看到重试按钮:

el = WebDriverWait(self.driver, 10).until(
  EC.element_to_be_clickable((By.NAME, "Try again")))
Run Code Online (Sandbox Code Playgroud)

或者启动检查成功,我们在自定义对象中收到 pin 输入请求:

el = WebDriverWait(self.driver, 20).until(
  EC.element_to_be_clickable((By.XPATH, "//Custom/Edit")))
Run Code Online (Sandbox Code Playgroud)

如何将其合并为一项检查而不必同时检查两者:我尝试了以下方法:

check = WebDriverWait(self.driver, 20).until(
  EC.element_to_be_clickable(
    (By.XPATH, "//Custom/Edit") or (By.NAME, "Try again")
))
Run Code Online (Sandbox Code Playgroud)

但只or检查第一个语句。

python selenium xpath css-selectors webdriverwait

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

显示错误 - 未知错误:DevToolsActivePort 文件不存在 - 它是电子应用程序(我使用的是 Windows 操作系统))

当我运行代码时,它显示以下错误 - Electron application

org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist.
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T15:28:36.4Z'
System info: host: 'DESKTOP-GN8LLQU', ip: '192.168.1.20', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.2'
Driver info: driver.version: ChromeDriver
Run Code Online (Sandbox Code Playgroud)

我的代码:

ChromeOptions opt = new ChromeOptions();
// path of your Electron Application
opt.setBinary("D:\\FOS\\fiber-optic-system-electron\\release\\angular-electron 0.1.0.exe");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("chromeOptions", opt);
capabilities.setBrowserName("chrome");
System.setProperty("webdriver.chrome.driver", "E:\\chromedriver_win32 (6)\\chromedriver.exe");
WebDriver driver = new ChromeDriver(capabilities);
Run Code Online (Sandbox Code Playgroud)

selenium google-chrome selenium-chromedriver electron java-11

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

chromedriver.exe 运行约 8 个 chrome.exe 实例

我使用 Selenium 编写 UI 自动化测试。我注意到,当我创建 chromedriver.exe 实例时 -> ~8 chrome.exe 进程出现在任务管理器中。

运行 1 个测试时的任务管理器屏幕截图:

截图任务管理器

因此,当我并行运行时,假设有 8 个测试,任务管理器中有很多 chrome.exe 实例,它们使用一些端口并加载 CPU 和内存。

它是按设计工作的吗?为什么一个 chromedriver.exe 需要这么多 chrome.exe 实例?这是可配置的吗?

在我的代码中,我只有一个“Chrome”类。它的构造函数创建一个新的 chromedriver.exe 实例:

Chrome chrome = new Chrome();

public class Chrome
{
    public OpenQA.Selenium.Chrome.ChromeDriver Driver;

    public Chrome(bool incognitoMode = false, bool maximizeWindow = true)
    {
        ChromeOptions options = new ChromeOptions();
        if (incognitoMode)
        {
            options.AddArguments("--incognito");
        }

        Driver = new ChromeDriver(options);
        Driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(360);
        if (maximizeWindow)
            Driver.Manage().Window.Maximize();
    }
  /////////////////////////////////////////////
}
Run Code Online (Sandbox Code Playgroud)

selenium google-chrome webdriver selenium-chromedriver selenium-webdriver

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

如何使用 Selenium 和 Python 与 reCAPTCHA 音频元素交互

我想,点击按钮通过音频解析验证码,但是selenium没有检测到指定的“id”。

browser.get("https://www.google.com/recaptcha/api2/demo")
mainWin = browser.current_window_handle  
iframe = browser.find_elements_by_tag_name("iframe")[0]
browser.switch_to_frame(iframe)
CheckBox = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.ID ,"recaptcha-anchor"))).click()
sleep(4)
audio = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.ID ,"recaptcha-audio-button"))).click()
Run Code Online (Sandbox Code Playgroud)

python iframe selenium recaptcha webdriverwait

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

如何在python selenium中设置Chrome实验选项same-site-by-default-cookie

我想这应该有效:

from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_experimental_option('same-site-by-default-cookies', 'true')
driver = webdriver.Chrome(chrome_options=options)
Run Code Online (Sandbox Code Playgroud)

启用为未来 chrome 版本计划的相同站点 cookie 限制。不是,有错误:

selenium.common.exceptions.InvalidArgumentException: 
Message: invalid argument: cannot parse capability: goog:chromeOptions
from invalid argument: unrecognized chrome option: same-site-by-default-cookies
Run Code Online (Sandbox Code Playgroud)

我可以使用 chrome://flags 手动更改选项并查看它是否正常工作。但是我想自动化它并运行测试脚本来查看它。

这里有 java 代码:https : //groups.google.com/forum/#!topic/ chromedriver-users/ cI8hj7eihRo 可以做到,但我不确定如何将其传输到 python。

是否有任何参考资料可以帮助我设置此选项或其他选项?

selenium google-chrome python-3.x selenium-chromedriver samesite

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

如何使用 Python 查找 Pycharm 的版本

我有一个程序可以从我的系统中获取版本(selenium、python 和 chrome),并将其与在线最新版本进行比较。

这是从我的系统获取 pythons 版本的代码

    pythonVersion = platform.python_version()
    finalVersion = "Python " + pythonVersion
Run Code Online (Sandbox Code Playgroud)

现在我的主要问题是尝试使用代码获取 Pycharms 版本。如果有人知道如何做到这一点,那将会很有帮助

python version pycharm

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

使用类名并包含文本的 XPath

我正在寻找如何查找具有类并包含文本的元素的答案。

我有两个答案。

对我来说,只有第二个答案有效。任何人都可以解释“包含文本”部分的区别吗?因为两个答案都没有提及。

selenium xpath webdriver xpath-1.0 selenium-webdriver

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

Python Selenium:等待元素可点击 - 使用 find_elements 找到元素

我正在构建一个网络抓取工具,它循环访问地址列表并在房地产网站上搜索它们。然后,它会根据我们已经了解的有关房产的信息更新一些下拉列表,然后再抓取各种信息,例如预期租金收益率。

搜索完每个地址后,可能需要一些时间才能将所需元素(例如“bathrooms_dropdown”)加载到网站上。我一直在使用它来管理它,time.sleep(x)但这很慢且不可靠,并且implictly_wait(60)似乎没有任何效果,因为我仍然经常收到“元素不存在/无法找到”错误。

我确信我需要实现 WebDriverWait,但在将其实现到我的代码中时无法计算出语法。我还没有看到任何与此结合使用的例子driver.find_elements()

任何帮助将不胜感激!

driver.get(url)
driver.implicitly_wait(60)   

# find search bar and search for address
searchBar = driver.find_element(by = By.ID, value = 'react-select-3-input')
searchBar.send_keys(address)
searchButton = driver.find_element(By.CLASS_NAME, value='sc-1mx0n6y-0').click()

# wait for elements to load
time.sleep(3) # REPLACE THIS

# find dropdown and click to open it
bathrooms_dropdown = driver.find_elements(By.CLASS_NAME, value = 'css-19bqh2r')[-2]
bathrooms_dropdown.click()  
Run Code Online (Sandbox Code Playgroud)

python selenium selenium-webdriver webdriverwait expected-condition

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