我正在尝试使用 IE 在 java selenium 中进行测试,但我的问题是我必须继续在保护模式下配置设置,这是已弃用功能的替代方法
WebDriver driver = new InternetExplorerDriver(cap);
Run Code Online (Sandbox Code Playgroud)
因为我希望在没有人工交互的情况下实现此自动化。我在 Eclipse 中使用这段代码,它在我的代码中根本没有任何效果,上面是用黄线荧光笔勾勒出来的,这表明它已被弃用。那么是否有一个新函数可以实现此目的,这是我一直用于完整性检查的代码
DesiredCapabilities cap = DesiredCapabilities.internetExplorer();
cap.setCapability("nativeEvents", false);
cap.setCapability("unexpectedAlertBehaviour", "accept");
cap.setCapability("ignoreProtectedModeSettings", true);
cap.setCapability("disable-popup-blocking", true);
cap.setCapability("enablePersistentHover", true);
cap.setCapability("ignoreZoomSetting", true);
cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
Run Code Online (Sandbox Code Playgroud) java selenium selenium-webdriver selenium-iedriver mutablecapabilities
假设我没有Grid设置,我可以从Selenium WebDriver启动的最大并发Chrome线程数是多少?
是5吗?而且对Chrome Headless也适用吗?
connection selenium http persistent-connection httpconnection
我正在努力将以下 Xpath 转换为 CSS:“//form[@id=\'giftcard-form\']/div[3]/div/button”。我知道我可以将 Xpath 用于我的 selenium JS,但由于某些奇怪的原因,它在我的情况下不起作用。我成功地转换了一个更简单的并在脚本中使用它,但我无法正确完成这个。任何人都可以帮忙吗?
我正在尝试通过webWhatsapp从聊天中打印我的消息之一。
我可以通过“控制台”选项卡中的Javascript完成此操作
recived_msg = document.getElementsByClassName('XELVh selectable-text invisible-space copyable-text') // returns an array of the chat
recived_msg[5].innerText // shows me the 4th message content
Run Code Online (Sandbox Code Playgroud)
问题是我试图在python上做同样的事情,但对我不起作用。
这是我尝试过的:
from selenium import webdriver
recived_msg = driver.find_element_by_class_name('XELVh selectable-text invisible-space copyable-text')
final = recived_msg[5].innerText #doesnt work for some reason
Run Code Online (Sandbox Code Playgroud)
我遇到的错误是:消息:无效的选择器:不允许使用复合类名
我对javascript有点陌生,所以很抱歉造成误会,并感谢您的帮助!:)
我有我在本地机器上使用的代码:
from selenium import webdriver
chrom_path = r"C:\Users\user\sof\chromedriver_win32\chromedriver.exe"
driver = webdriver.Chrome(chrom_path)
link = 'https://www.google.com/'
driver.get(link)
s = driver.page_source
print((s.encode("utf-8")))
driver.quit()
Run Code Online (Sandbox Code Playgroud)
并且此代码返回该网站的页面源,但是当我在Linux服务器centos7上使用此代码时:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
options.add_argument('--no-sandbox')
driver = webdriver.Chrome(executable_path="/usr/local/bin/chromedriver", chrome_options=options)
driver.get("https://www.google.com")
s = driver.page_source
print((s.encode("utf-8")))
driver.quit()
Run Code Online (Sandbox Code Playgroud)
这段代码也应该返回页面源代码,但这段代码返回:
b'<html><head>\n<title>Access Denied</title>\n</head><body>\n<h1>Access Denied</h1>\n \nYou don\'t have permission to access "http://www.newark.com/" on this server.<p>\nReference #18.456cd417.1576243477.e007b9f\n\n\n</p></body></html>'
Run Code Online (Sandbox Code Playgroud)
有人知道为什么相同的代码在不同的操作系统上的工作方式不同吗?
python selenium user-agent selenium-chromedriver google-chrome-headless
我正在使用 Selenium Python 来定位标签元素。我想使用::before来定位它,因为这是一个弹出窗口。
<div class="crow" grp="0" grpname="Pizza Size">
::before
<label class="label0" cid="1">
<input type="radio" name="0" coname="M" sname="" price="9.99" value="392">M<b class="ip">9.99</b>
</label>
<label class="label0" cid="1"><input type="radio" name="0" coname="L" sname="" price="11.99" value="393">L<b class="ip">11.99</b>
</label><div style="clear:both">
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我不知道如何使用::before来定位它,有朋友可以帮忙吗?
python selenium css-selectors pseudo-element selenium-webdriver
因此,我尝试使用运行测试,当我从 cmd 运行它时,mvn test -P它给了我,尽管它在 eclipse 本身中运行良好。java.lang.NoClassDefFoundError: org/openqa/selenium/WrapsElement
我有我的页面类src/main/java和我的测试src/test/java,我只是不明白为什么它在 Eclipse 中工作得很好,但在命令提示符下却不能。我认为它与 pom.xml 有关,但我不确定
这是我的 pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>selenium</groupId>
<artifactId>taf</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>taf</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${testNGSuite}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>${project.basedir}/target/classes</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>com.github.javafaker</groupId>
<artifactId>javafaker</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId> …Run Code Online (Sandbox Code Playgroud) 我有使用 Spring Boot 开发的基于硒的 Web 应用程序。该服务器位于谷歌云服务器的虚拟机实例。
请在下面找到有关版本的详细信息。
Spring Boot - 2.0.0.RELEASE
硒 - 3.9.1
Linux - Debian 4.9.130-2 (2018-10-27) x86_64 GNU/Linux
Chrome 驱动程序 - 2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881)
谷歌浏览器 - 70.0.3538.110
JDK - 1.8.0_232
从过去几天开始,我面临一个奇怪的问题,应用程序在营业时间开始时运行良好,但几个小时后变得不稳定,整个应用程序停止工作,甚至用户无法登录。在为此问题挖掘了更多信息后,我从服务器日志中发现了以下错误。我必须重新启动 VM 实例才能修复它。
重新启动后,它可以正常工作几个小时,然后我们再次面临同样的问题。
此外,我注意到在发送电子邮件时我们面临以下问题,该问题在几分钟前可以正常工作。

我还验证了服务器资源使用情况,但没有发现任何可疑活动。我在谷歌上搜索了这个问题,但大多数解决方案都是针对第一次运行时遇到的问题提供的。但是,就我而言,它可以正常工作几个小时,然后开始出现此问题。
请帮助我了解此问题的问题和根本原因。如果您也可以提出解决方案,那就更好了。
提前致谢。
java selenium google-chrome selenium-chromedriver spring-boot
我刚刚卸载了 Chrome,因为它表现得很奇怪(现已修复),之后 Python 中的 Selenium 无法识别 Chrome 驱动程序二进制文件,这非常奇怪,因为它应该完全不受影响,并且位于不同的位置和不同的版本从我在桌面上使用的 Chrome 来看,代码如下,并且已经工作多年了。
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--load-extension='+exension_path)
driver = webdriver.Chrome(executable_path=chrome_driver_folder,options=chrome_options)
Run Code Online (Sandbox Code Playgroud)
有人知道到底发生了什么事吗?我收到以下错误:
WebDriverException: Message: unknown error: cannot find Chrome binary
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.18362 x86_64)
Run Code Online (Sandbox Code Playgroud) python selenium google-chrome selenium-chromedriver selenium-webdriver
由于某种原因,在添加一系列 WebDriver 选项后,我的 Python 代码显示为无法访问。有谁知道为什么会发生这种情况以及如何解决它?

代码本身如下:
class DriverOptions(object):
def __init__(self):
self.options = Options()
self.options.add_argument('--no-sandbox')
self.options.add_argument('--start-maximized')
self.options.add_argument('--start-fullscreen')
self.options.add_argument('--single-process')
self.options.add_argument('--disable-dev-shm-usage')
self.options.add_argument("--incognito")
self.options.add_argument('--disable-blink-features=AutomationControlled')
self.options.add_argument('--disable-blink-features=AutomationControlled')
self.options.add_experimental_option('useAutomationExtension', False)
self.options.add_experimental_option("excludeSwitches", ["enable-automation"])
self.options.add_argument("disable-infobars")
self.helperSpoofer = Spoofer()
self.options.add_argument('user-agent={}'.format(self.helperSpoofer.userAgent))
self.options.add_argument('--proxy-server=%s' % self.helperSpoofer.ip)
Run Code Online (Sandbox Code Playgroud) selenium web-crawler python-3.x selenium-chromedriver chrome-options
selenium ×9
java ×3
python ×3
python-3.x ×2
xpath ×2
connection ×1
http ×1
javascript ×1
maven ×1
spring-boot ×1
user-agent ×1
web-crawler ×1
webdriver ×1