小编Ben*_*hak的帖子

Python Selenium 2.39和Firefox 26

我试图用unittest脚本执行一些selenium但我得到以下错误

Starting at: "Sat Dec 07 14:43:17 2013"
E
======================================================================
ERROR: test_template (__main__.ManageTemplates)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "template.py", line 70, in tearDown
    self.driver.quit()
  File "C:\Program Files (x86)\Python27\lib\site-packages\selenium-2.38.1-py2.7.egg\selenium\webdriver\firefox\webdriver.py", line 66, in quit
    RemoteWebDriver.quit(self)
  File "C:\Program Files (x86)\Python27\lib\site-packages\selenium-2.38.1-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 454, in quit
    self.execute(Command.QUIT)
  File "C:\Program Files (x86)\Python27\lib\site-packages\selenium-2.38.1-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 162, in execute
    response = self.command_executor.execute(driver_command, params)
  File "C:\Program Files (x86)\Python27\lib\site-packages\selenium-2.38.1-py2.7.egg\selenium\webdriver\remote\remote_connection.py", line 350, in execute
    return self._request(url, method=command_info[0], data=data)
  File "C:\Program Files (x86)\Python27\lib\site-packages\selenium-2.38.1-py2.7.egg\selenium\webdriver\remote\remote_connection.py", line 381, in _request
    self._conn.request(method, parsed_url.path, data, headers) …
Run Code Online (Sandbox Code Playgroud)

python firefox web2py selenium-webdriver python-unittest

11
推荐指数
1
解决办法
3067
查看次数

selenium没有在FirefoxProfile中设置downloaddir

我想自动下载文件并将它们保存在目录中,一切都已完成,但firefox仍然保存用户下载文件夹中的文件,例如 C:\users\root\Downloads

PyWebBot类中的函数

@staticmethod
def FirefoxProfile(path, handlers):
    from selenium import webdriver

    profile = webdriver.FirefoxProfile()
    profile.set_preference("browser.download.folderList",1)
    profile.set_preference("browser.download.manager.showWhenStarting",False)
    profile.set_preference("browser.download.dir", path)
    profile.set_preference("browser.download.downloadDir", path)
    profile.set_preference("browser.download.defaultFolder", path)
    profile.set_preference("browser.helperApps.alwaysAsk.force", False)
    profile.set_preference("browser.helperApps.neverAsk.saveToDisk", handlers)
    profile.set_preference("pdfjs.disabled", True)
    profile.update_preferences()

    return profile
Run Code Online (Sandbox Code Playgroud)

然后

 def setUp(self):
        self.profile = PyWebBot.FirefoxProfile(config['downloads'], config['handlers'])
        self.driver = webdriver.Firefox(self.profile)
    ...
    ...
Run Code Online (Sandbox Code Playgroud)

配置:

config['downloads'] = 'Q:/web2py_src/web2py/applications/internet2letter/private/testing/selenium/downloads'
config['handlers'] = 'application/pdf'
Run Code Online (Sandbox Code Playgroud)

python firefox selenium

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

xpath的硒计数元素

我有一个包含许多下载链接的表格的网页,我想让 selenium 点击最后一个:

桌子:

item1 Download
item2 Download
item3 Download
Run Code Online (Sandbox Code Playgroud)

selenium 一定要点击Downloadnextitem3

我使用 xpath 查找所有元素,然后以这种方式获取返回数组或字典的大小

x = bot._driver.find_element_by_xpath("//a[contains(text(),'Download')]").size()
Run Code Online (Sandbox Code Playgroud)

但我总是收到这个错误

TypeError: 'dict' object is not callable
Run Code Online (Sandbox Code Playgroud)

我尝试使用get_xpath_countmethode,但python中的selenium中不存在methode!

我想到了另一种解决方案,但我不知道该怎么做,如下所示

x = bot._driver.find_element_by_xpath("(//a[contains(text(),'Download')])[size()-1]")
Run Code Online (Sandbox Code Playgroud)

或者

x = bot._driver.find_element_by_xpath("(//a[contains(text(),'Download')])[last()]")
Run Code Online (Sandbox Code Playgroud)

或者是其他东西

python selenium xpath web2py

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

在python中将`QTableWidget`中的整列设置为只读

我想将表中的一列设置为只读!我尝试了所有可能的标志组合但没有成功

    item = QtGui.QTableWidgetItem()
    from operator import xor
    item.setFlags(xor(item.flags(),QtCore.Qt.ItemIsEditable))
    self.Table.setHorizontalHeaderItem(4, item)
Run Code Online (Sandbox Code Playgroud)

我也试过and not!=^操作符,但列项目仍然是可编辑的


更新

我想我误解了这一点!我想当我将 Horizo​​ntalHeaderItem 在一列中设置为不可编辑时,这将使该列中的所有新项目在使用类似操作时自动不可编辑insertRow()

插入新行后,我对每个新添加的项目执行了这些功能!

        tableWidget.insertRow(row+1)
        if  tableWidget is self.myTable:
            item = QtGui.QTableWidgetItem()
            item.setFlags(item.flags() != QtCore.Qt.ItemIsEditable)
            tableWidget.setItem(row+1, 4, item)
Run Code Online (Sandbox Code Playgroud)

我认为一个更好(但更复杂)的解决方案是使用setItemDelegateForColumn()QtGui.QItemDelegate()创建一个只读 costum QTableWidgetItem,每次插入或创建新行时都会添加它


编辑

好吧,我尝试使用setItemDelegateForColumn()QtGui.QItemDelegate()如上所述,但我收到以下警告

> python main.py
sys:1: RuntimeWarning: Invalid return value in function QItemDelegate.createEdit
or, expected PySide.QtGui.QWidget, got PySide.QtGui.QTableWidgetItem.
Run Code Online (Sandbox Code Playgroud)

我的代码是

class QTableWidgetDisabledItem(QtGui.QItemDelegate):
    """
    """
    def __init__(self, parent):

        QtGui.QItemDelegate.__init__(self, parent)

    def …
Run Code Online (Sandbox Code Playgroud)

python qt pyside qt5

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

带有 Tkinter 的 Python 小部件表

我想在 Python 下使用 Tkinter 将表格放入 GUI 中的标签框架中,表格不仅包含静态数据,还包含按钮、输入条目、检查按钮等小部件

例如:

表格1:

[ Nr. | Name | Active |  Action  ]
----------------------------------
[ 1   |  ST  |  [x]   | [Delete] ]
[ 2   |  SO  |  [ ]   | [Delete] ]
[ 3   |  SX  |  [x]   | [Delete] ]
Run Code Online (Sandbox Code Playgroud)

[x]是一个检查按钮并且[Delete]是一个按钮

python tkinter

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

QGridLayout 删除间距

我有一个QTableWidget和 6QPushBotton我想以这种方式将它们放在布局中

在此处输入图片说明

按钮之间只有很小的间距

但是使用QGridLayout使它看起来像这样

在此处输入图片说明

代码:

    tab_Memory_layout = QtGui.QGridLayout()
    tab_Memory_layout.setVerticalSpacing(0)
    tab_Memory_layout.setAlignment(QtCore.Qt.AlignTop)
    tab_Memory_layout.addWidget(self.MemoryTable, 0, 0)
    tab_Memory_buttons = QtGui.QGridLayout()
    tab_Memory_buttons.setSpacing(5)
    tab_Memory_buttons.addWidget(self.pushButton_add_memory, 0, 0, QtCore.Qt.AlignTop)
    tab_Memory_buttons.addWidget(self.pushButton_up_memory, 1, 0, QtCore.Qt.AlignTop)
    tab_Memory_buttons.addWidget(self.pushButton_down_memory, 2, 0, QtCore.Qt.AlignTop)
    tab_Memory_buttons.addWidget(self.pushButton_top_memory, 3, 0, QtCore.Qt.AlignTop)
    tab_Memory_buttons.addWidget(self.pushButton_bottom_memory, 4, 0, QtCore.Qt.AlignTop)
    tab_Memory_buttons.addWidget(self.pushButton_delete_memory, 5, 0, QtCore.Qt.AlignTop)
    tab_Memory_layout.addLayout(tab_Memory_buttons, 0, 1)
    self.tab_Memory.setLayout(tab_Memory_layout)
Run Code Online (Sandbox Code Playgroud)

我试过了,setRowStretch(i, 0), setVerticalSpacing(0)但没有帮助!

我也用QGridLayout,并QVBoxLayout为Bottons集团,它的工作原理,但所有按钮都在底部对齐,虽然我用AlignTop的每个元素和布局

qt pyqt pyside qt5

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

haskell迭代列表推导

我想在Haskell中这样做

for MyString = "ab"n = 4结果应该>

["aaaa","aaab","aaba","aabb","abaa","abab","abba","abbb","baaa","baab","baba","babb","bbaa","bbab","bbba","bbbb"]
Run Code Online (Sandbox Code Playgroud)

haskell

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