草庐IT

pytest-selenium

全部标签

python - 尝试访问命令行变量时出现 Pytest KeyError

我用一个新的更简单的假设置重新创建了这个问题。我有一个框架需要来自pytest的命令channel变量。此变量称为环境,但当我尝试访问该变量时,我得到一个AttributeError:“模块”对象没有属性“配置”。这是我的测试设置:我知道py.test按以下顺序加载:Pytest插件外部插件conftest.py文件,从外层文件到内层文件。我想我遇到了一个问题,当我加载内部conftest.py时,我尝试导入框架。当我导入框架时,它会尝试访问py.test变量。这个变量,即使pytest已经在我的outer-conftest.py的pytest_addoption()部分中看到它,还没

python - 通过 Selenium : "Allowing web_page contexts requires supplying a value for matches" 的 Chrome Webdriver 错误消息

我正在运行一个已编译的Python脚本,该脚本使用Selenium启动一个ChromeWebdriversession,该session访问一个站点并执行一些任务。该脚本的行为与我预期的一样,除了它在我第一次启动webdriver时向控制台打印一条“错误”消息。错误如下:[2460:7268:1121/133303:ERROR:base_feature_provider.cc(122)]manifestTypes:Allowingweb_pagecontextsrequiressupplyingavalueformatches.谁知道这是什么意思?就像我上面所说的,脚本的行为似乎符合我

python - Proxy+Selenium+PhantomJS 不能改变User-Agent

在phantomjs中使用代理时,它使用默认的python用户代理。运行:Ubuntu14.04上的Python3.5.1service_args=[]ifself.proxy:service_args.extend(['--proxy={}:{}'.format(self.proxy.host,self.proxy.port),'--proxy-type={}'.format(self.proxy.proto),])ifself.proxy.usernameandself.proxy.password:service_args.append('--proxy-auth={}:{}'.

python - 使用 pytest fixtures 的测试可以交互运行吗?

我有一些使用pytest和fixtures编写的测试,例如:classTestThing:@pytest.fixture()deftemp_dir(self,request):my_temp_dir=tempfile.mkdtemp()deffin():shutil.rmtree(my_temp_dir)request.addfinalizer(fin)returnmy_temp_dirdeftest_something(self,temp_dir)withopen(os.path.join(temp_dir,'test.txt'),'w')asf:f.write('test')这在从

python - Selenium Webdriver/Beautifulsoup + 网页抓取 + 错误 416

我正在使用Python中的seleniumwebdriver和Proxy进行网络抓取.我想使用此抓取浏览超过10k页的单个站点。问题使用此代理我只能发送一次请求。当我在同一个链接或本网站的另一个链接上发送另一个请求时,我会收到416错误(使用防火墙阻止IP的一种)持续1-2小时。注意:我可以使用此代码抓取所有正常网站,但该网站有某种安全措施阻止我抓取。这是代码。profile=webdriver.FirefoxProfile()profile.set_preference("network.proxy.type",1)profile.set_preference("network.pr

python - 初始化selenium webdriver时如何修复python-selenium错误 "connection refused"?

我在非公开网页上运行非常复杂的python-selenium测试。在大多数情况下,这些测试运行良好,但有时其中一个测试会在webdriver本身的初始化过程中失败。提示:尝试初始化网络驱动程序时会发生此错误,即在执行以下操作时:#Startofthetestsmydriver=webdriver.Firefox(firefox_profile=profile,log_path=logfile)#ERRORHAPPENSHERE#Doingotherstuffhere....#Doingtestshere....#Doingshutdownheremydriver.quit()这是此类错

Python 使用 Selenium 和 Beautiful Soup 抓取 JavaScript

我正在尝试使用BS和Selenium抓取启用JavaScript的页面。到目前为止,我有以下代码。它仍然没有以某种方式检测到JavaScript(并返回空值)。在这种情况下,我试图在底部抓取Facebook评论。(检查元素将类显示为postText)感谢您的帮助!fromseleniumimportwebdriverfromselenium.common.exceptionsimportNoSuchElementExceptionfromselenium.webdriver.common.keysimportKeysimportBeautifulSoupbrowser=webdrive

Python selenium 测试卡在 urlopen 中

我的应用依赖于:python3Django1.8轻松打印Selenium它在开发和生产环境中完美运行,但在使用selenium进行测试时却不是。使用weasyprint,我从HTML创建一个PDF,这个库使用urllib下载CSS(例如http://localhost:8081/static/lib/bootstrap/css/bootstrap.min.css),但它在打开这些时挂起(没有错误,只是卡住了)。如果我在挂起时直接在浏览器中输入此url,则会显示CSS。使用的命令:./manage.pytesttests.test_account.HomeNewVisitorTest测试

python - selenium python 点击​​元素没有任何反应

我正在尝试使用Python上的WebDriver在Selenium中点击Google主页上的Gmail链接。我的代码基本上复制了此处找到的代码:WhyCantIClickanElementinSelenium?我的代码:importselenium.webdriveraswebdriverfirefox=webdriver.Firefox()firefox.get("http://www.google.ca")element=firefox.find_element_by_xpath(".//a[@id='gb_23']")element.click()网络驱动程序加载页面,然后什么也

python - Selenium:如何禁用 firefox 和 python 的图像加载?

我看过类似的问题,一个应该是答案,但是当我尝试时,它只给出了部分解决方案。我指的是这个问题:DisableimagesinSeleniumPython我的问题是我尝试了解决方案,但一些图像没有出现,但图像来自:正在加载。有没有办法告诉firefox/selenium不要获取它?如果没有,有没有办法从我返回的dom元素中丢弃它,通过:self._browser.get(url)content=self._browser.page_source例如,通过在dom树上进行某种查找替换?浏览器配置与上一个问题的浏览器相同:firefox_profile=webdriver.FirefoxPro