想了解如何使用Selenium针对Firefox和Chrome禁用推送通知?的新动态吗?本文将为您提供详细的信息,此外,我们还将为您介绍关于asp.net–在Firefox和Chrome中启用了禁用按
想了解如何使用Selenium针对Firefox和Chrome禁用推送通知?的新动态吗?本文将为您提供详细的信息,此外,我们还将为您介绍关于asp.net – 在Firefox和Chrome中启用了禁用按钮、Centos 7.6 安装 selenium+firefox+google chrome(支持 xshell 运行)、Centos 7.6 安装selenium+firefox+google chrome(支持xshell运行)、cucumber; Selenium WebDriver-如何使用Google Chrome浏览器代替Firefox作为测试浏览器的新知识。
本文目录一览:- 如何使用Selenium针对Firefox和Chrome禁用推送通知?
- asp.net – 在Firefox和Chrome中启用了禁用按钮
- Centos 7.6 安装 selenium+firefox+google chrome(支持 xshell 运行)
- Centos 7.6 安装selenium+firefox+google chrome(支持xshell运行)
- cucumber; Selenium WebDriver-如何使用Google Chrome浏览器代替Firefox作为测试浏览器
如何使用Selenium针对Firefox和Chrome禁用推送通知?
我想通过Selenium Webdriver启动Firefox浏览器时禁用通知。我找到了这个答案,但是它已被弃用,在Firefox上对我不起作用(尽管它在Chrome上可以完美运行)。
我将这种依赖关系用于我的 pom.xml :
<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.11.0</version></dependency>
答案1
小编典典如果您的用 例 是禁用 通知,则可以使用 以下选项:
- 要在 Firefox* 浏览器客户端中禁用 推送通知 ,请使用 FirefoxProfile 并将 密钥 dom.webnotifications.enabled 和 dom.push.enabled 以及所需的 值 传递为 false : *__****
System.setProperty("webdriver.gecko.driver", "C:\\path\\to\\geckodriver.exe");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile testprofile = profile.getProfile(“debanjan”);
testprofile.setPreference(“dom.webnotifications.enabled”, false);
testprofile.setPreference(“dom.push.enabled”, false);
DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setCapability(FirefoxDriver.PROFILE, testprofile);
FirefoxOptions opt = new FirefoxOptions();
opt.merge(dc);
WebDriver driver = new FirefoxDriver(opt);
driver.get("https://www.ndtv.com/”);
注意 :此方法使用存储在我的本地系统中的现有FirefoxProfile
名称为 debanjan 的现有文件,该文件是
根据在Windows
上
创建新的Firefox配置
文件中的文档
创建的
- 要在 Chrome* 浏览器客户端中禁用 通知 ,请借助 setExperimentalOption() 来传递一个 HashMap ,该 HashMap 包含 profile.default_content_setting_values.notifications ,其 Value 为 2 : __ *
System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
Map
prefs = new HashMap ();
prefs.put(“profile.default_content_setting_values.notifications”, 2);
prefs.put(“credentials_enable_service”, false);
prefs.put(“profile.password_manager_enabled”, false);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption(“prefs”, prefs);
options.addArguments(“start-maximized”);
options.addArguments(“disable-infobars”);
options.addArguments(“–disable-extensions”);
options.addArguments(“–disable-notifications”);
WebDriver driver = new ChromeDriver(options);
driver.get("https://www.ndtv.com/”);
asp.net – 在Firefox和Chrome中启用了禁用按钮
alt text http://i48.tinypic.com/2f0a81t.jpg
“DashBoard”和“Calendar”已禁用
“代理信息”已启用.
在这里,我使用常规的asp按钮与CSS.
我该怎么办?
解决方法
input[disabled="disabled"] { /* disabled styles */ }
Centos 7.6 安装 selenium+firefox+google chrome(支持 xshell 运行)
1. 查看 Linux 版本
[root@penguin selenium]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
2. 安装 selemium
2.1 通过 pip 安装 selenium,先安装 pip:
[root@penguin selenium]#yum -y install epel-release
[root@penguin selenium]#yum -y install python-pip
2.2 如果提示 pip 更新则执行如下命令:
[root@penguin selenium]#pip install --upgrade pip
2.3 pip 安装 selenium
[root@penguin src]# pip install selenium
2.4 卸载 Centos 自带的 Mozilla firefox
mv /etc/firefox/ /etc/firefox.bak
mv /usr/lib64/firefox/ /usr/lib64/firefox.bak
mv /usr/bin/firefox /usr/bin/firefox.old
2.5 下载、解压 firefox
[root@penguin src]# ls -l /usr/local/src/firefox-66.0.3.tar.bz2
-rw-r--r-- 1 root root 62089056 Apr 30 16:47 /usr/local/src/firefox-66.0.3.tar.bz2
[root@penguin src]#tar xjvf firefox-66.0.3.tar.bz2
2.6 创建虚拟显示
yum install Xvfb libXfont xorg-x11-fonts*
pip3 install pyvirtualdisplay
2.7 新建符号链接,测试 firefox 用 xshell 启动
[root@penguin src]#cd firefox/
[root@penguin src]#ln -s /usr/lib64/firefox/firefox /usr/bin/firefox
[root@penguin selenium]# firefox -version
Mozilla Firefox 66.0.3
[root@penguin src]#firefox 此处无报错firefox正常启动,如果有错误请在/etc/hosts保证有如下一行:
127.0.0.1 localhost
2.8 安装 google chrome, 解决 root 无法运行 chrome
yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
[root@penguin selenium]# google-chrome -version
Google Chrome 74.0.3729.108
解决 root 无法运行 chrome
vi /usr/bin/google-chrome
在文件尾部添加:
if [[ -n "$CHROME_USER_DATA_DIR" ]]; then
# Note: exec -a below is a bashism.
exec -a "$0" "$HERE/chrome" \
--user-data-dir="$CHROME_USER_DATA_DIR" "$@"
else
exec -a "$0" "$HERE/chrome" --user-data-dir="/root/.config/google-chrome/" \
"$@" --no-sandbox
fi
2.9 下载、配置 firefox 对应的 webdriver--geckodriver
cd /usr/local/src/
tar xzvf geckodriver-v0.24.0-linux64.tar.gz
cp /usr/local/bin/geckodriver /usr/bin/geckodriver
2.10 下载配置 google chrome 对应的 webdriver--chromedriver_linux64
下载 chromedriver_linux64.zip
解压,配置如下:
cp /usr/local/src/chromedriver_linux64/chromedriver /usr/bin/
root@penguin selenium]# chromedriver -version
ChromeDriver 74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29})
3. 测试
3.1 编写代码测试 firefox
#!/usr/bin/env python3
from selenium import webdriver
driver = webdriver.Firefox()
driver.get(''http://www.163.com'')
print(driver.title)
#driver.quit()
3.2 编写代码测试 google chrome
#!/usr/bin/env python3
from selenium import webdriver
driver = webdriver.Chrome()
driver.get(''https://www.baidu.com'')
print(driver.title)
driver.quit()
4. 异常问题解决
firefox:
File "/root/.pyenv/versions/3.6.4/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
keep_alive=True)
File "/root/.pyenv/versions/3.6.4/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/root/.pyenv/versions/3.6.4/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/root/.pyenv/versions/3.6.4/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/root/.pyenv/versions/3.6.4/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities
webdriver 与 firefox 版本不匹配,可以查找对应的 webdriver 版本解决
Traceback (most recent call last):
File "./test.py", line 8, in <module>
driver = webdriver.Firefox()
File "/root/.pyenv/versions/3.6.4/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 164, in __init__
self.service.start()
File "/root/.pyenv/versions/3.6.4/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 104, in start
raise WebDriverException("Can not connect to the Service %s" % self.path)
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service geckodriver
卸载系统自带的 firefox,重新安装并设置为 root 可以启动,同时参考步骤 2.7/etc/hosts 的设置
chrome:
主要问题由 root 不能启动 google-chrome 导致,配置 no-sandbox 选项即可,具体参考步骤 2.8
Centos 7.6 安装selenium+firefox+google chrome(支持xshell运行)
1. 查看Linux 版本
[[email protected] selenium]# cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core)
2. 安装selemium
2.1 通过pip 安装selenium,先安装pip:
[[email protected] selenium]#yum -y install epel-release
[[email protected] selenium]#yum -y install python-pip
2.2 如果提示pip更新则执行如下命令:
[[email protected] selenium]#pip install --upgrade pip
2.3 pip安装selenium
[[email protected] src]# pip install selenium
2.4 卸载Centos自带的Mozilla firefox
mv /etc/firefox/ /etc/firefox.bak mv /usr/lib64/firefox/ /usr/lib64/firefox.bak mv /usr/bin/firefox /usr/bin/firefox.old
2.5 下载、解压firefox
[[email protected] src]# ls -l /usr/local/src/firefox-66.0.3.tar.bz2 -rw-r--r-- 1 root root 62089056 Apr 30 16:47 /usr/local/src/firefox-66.0.3.tar.bz2
[[email protected] src]#tar xjvf firefox-66.0.3.tar.bz2
2.6 创建虚拟显示
yum install Xvfb libXfont xorg-x11-fonts* pip3 install pyvirtualdisplay
2.7 新建符号链接,测试firefox用xshell启动
[[email protected] src]#cd firefox/
[[email protected] src]#ln -s /usr/lib64/firefox/firefox /usr/bin/firefox
[[email protected] selenium]# firefox -version
Mozilla Firefox 66.0.3
[[email protected] src]#firefox 此处无报错firefox正常启动,如果有错误请在/etc/hosts保证有如下一行:
127.0.0.1 localhost
2.8 安装google chrome, 解决root无法运行chrome
yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
[[email protected] selenium]# google-chrome -version
Google Chrome 74.0.3729.108
解决root无法运行chrome
vi /usr/bin/google-chrome
在文件尾部添加:
if [[ -n "$CHROME_USER_data_dir" ]]; then # Note: exec -a below is a bashism. exec -a "$0" "$HERE/chrome" --user-data-dir="$CHROME_USER_data_dir" "[email protected]" else exec -a "$0" "$HERE/chrome" --user-data-dir="/root/.config/google-chrome/" "[email protected]" --no-sandBox fi
2.9 下载、配置firefox对应的webdriver--geckodriver
cd /usr/local/src/ tar xzvf geckodriver-v0.24.0-linux64.tar.gz cp /usr/local/bin/geckodriver /usr/bin/geckodriver
2.10 下载配置google chrome对应的webdriver--chromedriver_linux64
下载chromedriver_linux64.zip
解压,配置如下:
cp /usr/local/src/chromedriver_linux64/chromedriver /usr/bin/
[email protected] selenium]# chromedriver -version
ChromeDriver 74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/[email protected]{#29})
3. 测试
3.1 编写代码测试firefox
#!/usr/bin/env python3 from selenium import webdriver driver = webdriver.Firefox() driver.get(‘http://www.163.com‘) print(driver.title) #driver.quit()
3.2 编写代码测试google chrome
#!/usr/bin/env python3 from selenium import webdriver driver = webdriver.Chrome() driver.get(‘https://www.baidu.com‘) print(driver.title) driver.quit()
4. 异常问题解决
firefox:
File "/root/.pyenv/versions/3.6.4/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py",line 174,in __init__ keep_alive=True) File "/root/.pyenv/versions/3.6.4/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py",line 157,in __init__ self.start_session(capabilities,browser_profile) File "/root/.pyenv/versions/3.6.4/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py",line 252,in start_session response = self.execute(Command.NEW_SESSION,parameters) File "/root/.pyenv/versions/3.6.4/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py",line 321,in execute self.error_handler.check_response(response) File "/root/.pyenv/versions/3.6.4/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py",line 242,in check_response raise exception_class(message,screen,stacktrace) selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities
webdriver与firefox版本不匹配,可以查找对应的webdriver版本解决
Traceback (most recent call last): File "./test.py",line 8,in <module> driver = webdriver.Firefox() File "/root/.pyenv/versions/3.6.4/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py",line 164,in __init__ self.service.start() File "/root/.pyenv/versions/3.6.4/lib/python3.6/site-packages/selenium/webdriver/common/service.py",line 104,in start raise WebDriverException("Can not connect to the Service %s" % self.path) selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service geckodriver
卸载系统自带的firefox,重新安装并设置为root可以启动,同时参考步骤2.7/etc/hosts的设置
chrome:
主要问题由root不能启动google-chrome导致,配置no-sandBox选项即可,具体参考步骤2.8
cucumber; Selenium WebDriver-如何使用Google Chrome浏览器代替Firefox作为测试浏览器
对于我的Rails 3.1应用程序上的Cucumber场景,我使用了@javascript标记,因此Selenium已激活。我收到以下错误:
Could not find Firefox binary (os=macosx). Make sure Firefox is installed or set the path manually with Selenium::WebDriver::Firefox::Binary.path= (Selenium::WebDriver::Error::WebDriverError)
如果可能的话,我想使用Google Chrome浏览器作为浏览器-而不是Firefox(我尚未安装)。这可能吗?该怎么办?
实际上,Cucumber / Selenium不应检测并使用浏览器吗?
====编辑====
添加后
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app,:browser => :chrome)
end
…到features / support / env.rb,我现在收到此错误:
Unable to find the chromedriver executable. Please download the server from http://code.google.com/p/chromium/downloads/list and place it somewhere on your PATH. More info at http://code.google.com/p/selenium/wiki/ChromeDriver. (Selenium::WebDriver::Error::WebDriverError)
./features/step_definitions/web_steps.rb:45:in `/^(?:|I )am on (.+)$/'
features/update_memories.feature:11:in `Given I am on the home page'
我是从这里下载的,并且尝试将chromedriver可执行文件放在/
usr / bin中,但是仍然出现上述错误。
====编辑2 ====
进一步执行以下步骤并运行“ sudo chmod + x / usr / bin / chromedriver”后,在运行黄瓜之后,我现在收到一个新错误:
@javascript
Scenario: navigate to memory update page from home page # features/update_memories.feature:11
Given I am on the home page # features/step_definitions/web_steps.rb:44
unable to connect to chromedriver http://127.0.0.1:57870 (Selenium::WebDriver::Error::WebDriverError)
./features/step_definitions/web_steps.rb:45:in `/^(?:|I )am on (.+)$/'
features/update_memories.feature:12:in `Given I am on the home page'
When I activate the edit memory switch for the memory "I played" # features/step_definitions/memories/memory_steps.rb:5
Then I should be on the edit memory page for the memory "I played" # features/step_definitions/web_steps.rb:187
PGError: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
: ROLLBACK (ActiveRecord::StatementInvalid)
帮助赞赏!越来越近…
今天关于如何使用Selenium针对Firefox和Chrome禁用推送通知?的介绍到此结束,谢谢您的阅读,有关asp.net – 在Firefox和Chrome中启用了禁用按钮、Centos 7.6 安装 selenium+firefox+google chrome(支持 xshell 运行)、Centos 7.6 安装selenium+firefox+google chrome(支持xshell运行)、cucumber; Selenium WebDriver-如何使用Google Chrome浏览器代替Firefox作为测试浏览器等更多相关知识的信息可以在本站进行查询。
本文标签: