小编Deb*_*anB的帖子

PageFactory中的StaleElementReference异常

我正在尝试学习PageFactory模型.我理解这样一个事实,当我们这样做时initElements,WebElements就位于其中.比如说,我点击了一个webelement,因此DOM中的其他一个元素发生了变化.现在,显然我会在StaleElementReferenceException这里得到一个.我该如何解决这个问题?

我是否应该再次发现特定的WebElement知道DOM中的WebElement属性可能发生了变化?还是有另一种方法来处理这个问题?

selenium pageobjects selenium-webdriver page-factory staleelementreferenceexception

10
推荐指数
2
解决办法
4670
查看次数

使用Selenium在Python中滚动到页面顶部

我在使用Python和Selenium时遇到滚动到网页顶部的问题.

当页面由于某种原因加载时,您将被带到页面底部(这是由于修复).但是,当我试图滚动到顶部时,它不起作用.

我尝试了以下方法:

self.driver.execute_script("scroll(0, -250);")
Run Code Online (Sandbox Code Playgroud)

self.driver.execute_script("scroll(0, 0);")
Run Code Online (Sandbox Code Playgroud)

我也试过找到元素然后滚动到它:

self.driver.execute_script("arguments[0].scrollIntoView()", element)
Run Code Online (Sandbox Code Playgroud)

向上滚动到元素时,上面的scrollIntoView()代码可以正常工作.但是,它不能向上滚动.

我试过这个运行Chrome驱动程序和PhantomJs.

有什么建议?

javascript python selenium webdriver selenium-webdriver

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

如何在 Selenium Chrome Python 中设置窗口大小

以下用于调整 selenium chrome 窗口大小的代码不起作用:

driver.set_window_size(1920, 1080)
time.sleep(5)
size = driver.get_window_size()
print("Window size: width = {}px, height = {}px.".format(size["width"], size["height"]))
Run Code Online (Sandbox Code Playgroud)

其输出为:

Window size: width = 1044px, height = 788px
Run Code Online (Sandbox Code Playgroud)

我还尝试使用选项来设置驱动程序创建时的窗口大小(以及许多其他内容,参见下面的评论),但也无法使其工作:

options.add_argument("--window-size=1920,1080")
Run Code Online (Sandbox Code Playgroud)

我正在使用 selenium 3.14.0,chrome 驱动程序版本 72.0.3626.109 并在后台/无头模式下运行:我确实需要在后台运行我的代码,这意味着它会在后台自动启动。我认为无头(启动时与特定用户相关联)和背景(也是无头但可能不与特定用户相关联并且可能有其他特质)之间存在细微的区别 - 我开始认为这可能成为我的问题的一部分。

我想让 chrome 驱动程序工作,因为 firefox 不在后台运行(我需要),而 ie 很痛苦。

我想解决这个问题,因为当窗口很小时我看不到需要单击的元素。

python selenium google-chrome selenium-chromedriver google-chrome-headless

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

Timed out receiving message from renderer: 10.000 while capturing screenshot using chromedriver and chrome through Jenkins on Windows

OS: Windows 10 Browser: Chrome Browser version: Version 73.0.3683.86 (Official Build) (32-bit)

I am running selenium cucumber BDD project where I am verifying title of one page. I am using extent-report version4. Project running successfully in local. But when i am running it through Jenkins, its failing while capturing screenshot and showing below error.

If i remove the surfire plugin from pom.xml then the TEST is not running via Jenkins.

在詹金斯的执行Windows批处理命令选项中,我给出了以下命令

C:\Program Files (x86)\Jenkins\workspace\CucumberBDDFramework
mvn test
Run Code Online (Sandbox Code Playgroud)

TestRunner

    package com.accenture.TestRunner;

    import …
Run Code Online (Sandbox Code Playgroud)

windows selenium google-chrome jenkins selenium-chromedriver

10
推荐指数
1
解决办法
4363
查看次数

selenium.JavascriptException:javascript 错误:无法在“文档”上执行“elementFromPoint”:提供的双精度值是非有限的

使用 chrome 78 和 chromedriver78 当我单击音频文件或尝试使用 selenium 测试停止音频时,我收到此错误。

错误:

org.openqa.selenium.JavascriptException: javascript error: Failed to execute 'elementsFromPoint' on 'Document': The provided double value is non-finite.
Run Code Online (Sandbox Code Playgroud)

请注意,它仅发生在远程 webdriver 并且不一致。

错误堆栈跟踪:

当“item_1”元素的音频播放器在“[data-rcfid='checkbox_7']”中停止时

org.openqa.selenium.JavascriptException: javascript error: Failed to execute 'elementsFromPoint' on 'Document': The provided double value is non-finite.
  (Session info: chrome=78.0.3904.70)
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z'
System info: host: 'ip-10-0-10-137', ip: '10.0.10.137', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-71-generic', java.version: '1.8.0_111'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities {acceptInsecureCerts: true, browserName: chrome, browserVersion: 78.0.3904.70, chrome: …
Run Code Online (Sandbox Code Playgroud)

selenium webdriver selenium-chromedriver selenium-webdriver selenium-remotedriver

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

如何在 Selenium(使用 Python)中使用 Chrome DevTools 协议来捕获 HTTP 请求和响应?

我知道它Fetch Domain用于此目的,但我不知道如何准确地实现它。在 Selenium python 中,我使用以下代码来启用requestPaused事件的发出。

driver.execute_cdp_cmd("Fetch.enable",{})
driver.get('https://www.example.com')
Run Code Online (Sandbox Code Playgroud)

但我不知道如何处理requestPaused事件(我需要调用 1fulfillRequestcontinueRequest/ continueWithAuth)。结果,我的程序停止工作。如果有人能为我提供一个例子来帮助我理解它是如何工作的,我真的很感激。

selenium google-chrome-devtools fetch-api chrome-devtools-protocol selenium4

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

RequestsDependencyWarning: urllib3 (1.26.11) 或 chardet (3.0.4) 与使用 Selenium 和 ChromeDriverManager 的支持版本不匹配错误

我有这个脚本来访问我的互联网调制解调器并重新启动设备,但几周前停止工作。这是我的代码:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
service = Service(executable_path=ChromeDriverManager().install())
driver = webdriver.Chrome(service=service)
from selenium.webdriver.common.by import By

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')

driver = webdriver.Chrome(ChromeDriverManager().install(),options=chrome_options)

driver.get('http://192.168.15.1/me_configuracao_avancada.asp',)
user = driver.find_element(By.ID, "txtUser")
user.send_keys("support")
btnLogin = driver.find_element(By.ID, "btnLogin")
btnLogin.click()
driver.get('http://192.168.15.1/reboot.asp',)
reboot = driver.find_element(By.ID, "btnReboot")
reboot.click()
print("Modem Reiniciado!")
Run Code Online (Sandbox Code Playgroud)

现在,当我运行时,会返回此错误消息:

/usr/lib/python3/dist-packages/requests/__init__.py:89: RequestsDependencyWarning: urllib3 (1.26.11) or chardet (3.0.4) doesn't match a supported version!
  warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported "
Traceback (most …
Run Code Online (Sandbox Code Playgroud)

python selenium google-chrome selenium-chromedriver webdrivermanager-python

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

安装selenium-webdriver以与NodeJS + Selenium + Mocha一起使用的理想位置(在Windows上)

selenium-webdriver使用NodeJS+ Selenium+Mocha安装的理想位置是什么(在Windows上)

我刚开始用Selenium探索NodeJS.继续我将使用NodeJS + Selenium + Mocha

  1. 已安装node.js:

    C:\Users\AtechM_03>node -v
    v6.11.2
    
    Run Code Online (Sandbox Code Playgroud)
  2. 已安装npm:

    C:\Users\AtechM_03>npm -v
    3.10.10
    
    Run Code Online (Sandbox Code Playgroud)
  3. nodeclipse根据http://www.nodeclipse.org/updates/我和我的项目结构配置如下:

在此输入图像描述

现在,我不确定要安装的确切位置 selenium-webdriver

  1. selenium-webdriver根据(http://www.nodeclipse.org/updates/)安装在默认位置(通过命令行)

    C:\Users\AtechM_03>npm install selenium-webdriver
    C:\Users\AtechM_03
    `-- selenium-webdriver@3.5.0
      +-- jszip@3.1.3
      | +-- core-js@2.3.0
      | +-- es6-promise@3.0.2
      | +-- lie@3.1.1
      | | `-- immediate@3.0.6
      | +-- pako@1.0.5
      | `-- readable-stream@2.0.6
      |   +-- core-util-is@1.0.2
      |   +-- inherits@2.0.3
      |   +-- isarray@1.0.0
      |   +-- process-nextick-args@1.0.7
      |   +-- string_decoder@0.10.31
      |   `-- util-deprecate@1.0.2 …
    Run Code Online (Sandbox Code Playgroud)

javascript selenium mocha.js node.js selenium-webdriver

9
推荐指数
1
解决办法
681
查看次数

WebDriverException:未知错误:无法将窗口状态更改为最大化,当前状态正常,MAC OS X上的Chrome 70和Chromedriver 2.43

我们使用的是Chrome版本70.0.3538.67(官方版本)(64位),ChromeDriver 2.43.600229.Chrome窗口出现,但网址停留在"data:,".(下面的堆栈跟踪)

我们找到了使用Chrome版本69 w/chromedriver 2.43的解决方法,但Chrome仍然坚持要更新自己.

我们运行Selenium-java 3.4,htmlunit-driver 2.27,testng 6.9.4,junit 4.7 with maven-compiler-plugin 3.6.1,maven-surefire-plugin 2.22.0.

org.openqa.selenium.WebDriverException: unknown error: failed to change window state to maximized, current state is normal
  (Session info: chrome=70.0.3538.67)
  (Driver info: chromedriver=2.43.600229 (3fae4d0cda5334b4f533bede5a4787f7b832d052),platform=Mac OS X 10.13.6 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 107 milliseconds
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'edited', ip: 'edited', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.6', java.version: '1.8.0_131'
Driver info: …
Run Code Online (Sandbox Code Playgroud)

java macos selenium google-chrome selenium-chromedriver

9
推荐指数
1
解决办法
4054
查看次数

找到 reCAPTCHA 元素并点击它——Python + Selenium

我需要帮助。有网址:https://www.inipec.gov.it/cerca-pec/-/pecs/companies。我需要点击复选框验证码: 在此处输入图片说明

我的代码看起来像:

import os, urllib.request, requests, datetime, time, random, ssl, json, codecs, csv, urllib
from urllib.request import Request, urlopen
from urllib.request import urlretrieve
from datetime import datetime
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoAlertPresentException
from selenium.webdriver.chrome.options import Options

chromedriver = "chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
chrome_options = webdriver.ChromeOptions()
driver = webdriver.Chrome(executable_path=chromedriver, chrome_options=chrome_options)
driver.get("https://www.inipec.gov.it/cerca-pec/-/pecs/companies")
driver.switch_to_default_content()
element = …
Run Code Online (Sandbox Code Playgroud)

python selenium webdriver recaptcha webdriverwait

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