标签: splinter

使用Splinter发送密钥

我想使用Splinter测试自动完成框。我需要将“向下”和“输入”键发送到浏览器,但是这样做很麻烦。

我目前正在寻找一个输入框,并在该框中成功输入“ tes”

context.browser.find_by_xpath(\\some\xpath\).first.type('tes')
Run Code Online (Sandbox Code Playgroud)

我接下来要做的是向浏览器发送一些键,特别是“向下”键(选择第一个自动完成建议),然后发送“ enter”键选择该自动完成元素。

我已经尝试了广泛的搜索,但不知道如何执行此操作。

我什至尝试了一些JavaScript

script = 'var press = jQuery.Event("keypress"); press.keyCode = 34; press.keyCode = 13;'
context.browser.execute_script(script)
Run Code Online (Sandbox Code Playgroud)

但这不幸的是没有做任何事情

我正在使用的软件包:

django 1.6 django-behave == 0.1.2碎片0.6

当前配置是:
从splinter.browser import从django.test.client import浏览器import Client

context.browser = Browser('chrome')
context.client = Client()
Run Code Online (Sandbox Code Playgroud)

python django splinter python-behave

5
推荐指数
1
解决办法
2613
查看次数

使用Splinter/Selenium与iFrames交互[Python]

注意:Selenium或API包装Splinter for Selenium的解决方案很好!

我在使用Splinter API for Python在Twitter.com上与iframe交互时遇到了问题.

例如,

with Browser('firefox', profile_preferences= proxySettings) as browser:
    #...login and do other stuff here
    browser.find_by_id('global-new-tweet-button').click()
Run Code Online (Sandbox Code Playgroud)

这会弹出一个弹出框来输入推文.

如何使用Splinter与这个新盒子进行交互:1)填写消息2)点击"推特"(提交)...当然是编程的.

我尝试检查元素但它似乎没有嵌套在iframe中,但是它以iframe为目标.所以我不确定如何在弹出窗口中找到/交互元素.

我尝试手动键入消息,然后以编程方式单击tweet按钮:

browser.find_by_css('.btn.primary-btn.tweet-action.tweet-btn.js-tweet-btn').click()
Run Code Online (Sandbox Code Playgroud)

..但我收到错误:

ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with
Stacktrace:
    at fxdriver.preconditions.visible (file:///var/folders/z1/8rqrglqn2dj8_yj1z2fv5j700000gn/T/tmppRsJvd/extensions/fxdriver@googlecode.com/components/command-processor.js:10092)
    at DelayedCommand.prototype.checkPreconditions_ (file:///var/folders/z1/8rqrglqn2dj8_yj1z2fv5j700000gn/T/tmppRsJvd/extensions/fxdriver@googlecode.com/components/command-processor.js:12644)
    at DelayedCommand.prototype.executeInternal_/h (file:///var/folders/z1/8rqrglqn2dj8_yj1z2fv5j700000gn/T/tmppRsJvd/extensions/fxdriver@googlecode.com/components/command-processor.js:12661)
    at DelayedCommand.prototype.executeInternal_ (file:///var/folders/z1/8rqrglqn2dj8_yj1z2fv5j700000gn/T/tmppRsJvd/extensions/fxdriver@googlecode.com/components/command-processor.js:12666)
    at DelayedCommand.prototype.execute/< (file:///var/folders/z1/8rqrglqn2dj8_yj1z2fv5j700000gn/T/tmppRsJvd/extensions/fxdriver@googlecode.com/components/command-processor.js:12608)
Run Code Online (Sandbox Code Playgroud)

我非常希望使用Splinter实现我的目标,所以请不要提供替代方案,我知道还有其他方法.先感谢您!

javascript python iframe selenium splinter

5
推荐指数
1
解决办法
457
查看次数

我可以通过Python中的splinter模块以某种方式从页面上的下拉列表中选择特定元素

我可以通过Python中的splinter模块以某种方式从页面上的下拉列表中选择特定元素吗?

我有以下HTML代码:

<select id="xyz">
   <optgroup label="Group1">
      <option value="1">pick1</option>
      <option value="2">pick2</option>
   </optgroup>
   <optgroup label="Group2">
       <option value="3">pick3</option>
       <option value="4">pick4</option>
   </optgroup>
</select>
Run Code Online (Sandbox Code Playgroud)

假设我需要选择"pick3"选项.我该怎么做?

html python testing splinter

4
推荐指数
1
解决办法
5681
查看次数

如何使用python splinter lib在<span> </ span>之间获取文本

我想在我已经使用lib splinter之间得到文本

"<span id="stWelcomeInbox" class="nui-txt-impt">
1
</span>"
Run Code Online (Sandbox Code Playgroud)

PS:我不想下载页面并阅读为HTML代码可能re lib可用但我不知道如何使用它而无需下载该页面.我也不知道如何使用re lib.请帮我

html python web-scraping splinter

4
推荐指数
1
解决办法
2196
查看次数

是否可以使用splinter按文本选择选项(例如,当select选项没有值时)?

<select id = 'foo' name = 'foo'>
    <option>aaaaa</option>
    <option>bbbbb</option>
    <option>ccccc</option>
    <option>ddddd</option>
</select>
Run Code Online (Sandbox Code Playgroud)

似乎在命令"browser.select("foo",value)中"需要一个值.

这有解决方法吗?非常感谢.

splinter

4
推荐指数
1
解决办法
735
查看次数

在python splinter网络搜寻器中设置一个timout

尝试在python中设置超时,就像在ruby中一样。

我有一个链接,当我单击它时会打开一个弹出窗口,但无法访问它,因为它会导致脚本冻结,直到我杀死它为止。我几个月来一直在尝试访问此弹出窗口,而在ruby watir-webdriver中却没有任何乐趣。

我正在尝试使对弹出窗口的调用超时,然后访问弹出窗口。

@timeout(3)
try:
b.execute_script("javascript:openMdlWindow('InvestmentDetailOptions.aspx?IDAssetType=','620','600');if(window.document.RetValue == '2'){window.parent.LoadinIframe('InvestmentDetail.aspx?FromMenu=N&IDAssetType=','Investment Details > Full View','false');}")
except Exception, e:
print 'timeout!'
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激。

python webautomation selenium-chromedriver splinter

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

Django与splinter和phantomjs的速度非常缓慢

今天,我想Django的结合LiveServerTestCasesplinterphantomjs的webdriver.

这是我做的(简化版):

class Test(LiveServerTestCase):

    def setUp(self):
        self.browser = Browser('phantomjs')

    def tearDown(self):
        self.browser.quit()

    def test(self):
        self.browser.visit(self.live_server_url)
        self.assertIn("Hello world!", self.browser.title)
Run Code Online (Sandbox Code Playgroud)

有时测试运行正常 - 即使每个测试方法执行第二次.但有时它可以随机地花费约100秒来执行单个测试方法,或者它只是冻结,直到我没有耐心等待它完成.

django_nose用作测试运行器,并且我将--liveserver=localhost:8081-8181一系列端口传递给./manage.py test命令.

有没有办法加快速度?是否有其他网络测试跑步者哪个更快?

默认的Web驱动程序似乎在速度方面更可靠(每个测试方法1-3秒),但它仍然很慢.我也更喜欢无头浏览器进行测试.

python django selenium phantomjs splinter

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

如何使用Splinter查找元素值?

我有以下一段html:

<p class="attrs"><span>foo:</span> <strong>foo</strong></p>
<p class="attrs"><span>bar:</span> <strong>bar</strong></p>
<p class="attrs"><span>foo2:</span> <strong></strong></p>
<p class="attrs"><span>description:</span> <strong>description body</strong></p>
<p class="attrs"><span>another foo:</span> <strong>foooo</strong></p>
Run Code Online (Sandbox Code Playgroud)

我想使用splinter获取描述主体.我已经设法获得了一份p使用清单

browser.find_by_css("p.attrs")
Run Code Online (Sandbox Code Playgroud)

python dom screen-scraping web-scraping splinter

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

使用Python/Requests/BeautifulSoup进行高效的网页抓取

我正试图从芝加哥运输管理局的bustracker网站上获取信息.特别是,我想快速输出前两辆巴士的到达ETA.我可以用Splinter轻松地做到这一点; 但是我在无头Raspberry Pi模型B和Splinter加上pyvirtualdisplay上运行这个脚本会导致大量的开销.

有点像

from bs4 import BeautifulSoup
import requests

url = 'http://www.ctabustracker.com/bustime/eta/eta.jsp?id=15475'
r = requests.get(url)
s = BeautifulSoup(r.text,'html.parser')
Run Code Online (Sandbox Code Playgroud)

没有办法.所有数据字段都是空的(好吧,有 ).例如,当页面如下所示:

在此输入图像描述

当我使用Splinter执行类似搜索时,此代码段s.find(id='time1').text为我提供u'\xa0'了"12分钟"而不是"12分钟".

我没有和BeautifulSoup /请求结合; 我只想要一些不需要Splinter/pyvirtualdisplay开销的东西,因为项目要求我获得一个简短的字符串列表(例如上面的图像[['9','104th/Vincennes','1158','12 MINUTES'],['9','95th','1300','13 MINUTES']]),然后退出.

python beautifulsoup web-scraping python-2.7 splinter

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

接受ssl证书与marionette firefox webdrive python splinter

当使用python splinter firefox 47 marionette new webdriver时,它在访问我想要的网站时出现证书错误,我试图接受ssl证书与

browser = Browser('firefox',capabilities = {'marionette':True,'acceptSslCerts':True})

或使用trustAllSSLCertificates而不是acceptSslCerts,但仍然给我证书错误,有什么问题?

python firefox selenium webdriver splinter

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