小编nos*_*mus的帖子

PyQt5:QWebEngineView中的mouseClick和源代码

我有一个使用PyQt-5.5.1的工作脚本,我现在想要移植到一个新的PyQt版本(5.7).适应大多数事情很好,但我面临两个主要问题:(1)执行(模拟)鼠标点击,(2)访问(假设:打印)当前显示的网页的html源代码分别是QWebView或QWebEngineView.

例如,我可以使用PyQt-5.5.1中的QWebView执行以下操作:

QTest.mouseClick(self.wvTest, Qt.LeftButton, QPoint(x, y))
Run Code Online (Sandbox Code Playgroud)

frame = self.wvTest.page().mainFrame()
print(frame.toHtml().encode('utf-8'))
Run Code Online (Sandbox Code Playgroud)

我知道有关移植到QWebEngineView但无法将C++表示法转换为可用的Python代码的文档以及此页面.

如何在PyQt-5.7中将其改编为QWebEngineView?下面是PyQt-5.5.1的一个完整工作片段,它对于新的PyQt版本失败了:

  • 对于Button1:根本没有鼠标点击反应.
  • 对于Button2:,AttributeError: 'QWebEnginePage' object has no attribute 'mainFrame'当我删除大型机()时:TypeError: toHtml(self, Callable[..., None]): not enough arguments.

import sys
from PyQt5.QtWidgets import QWidget, QPushButton, QApplication
from PyQt5.QtCore import QRect, Qt, QUrl, QPoint, QEvent
from PyQt5.QtTest import QTest
from PyQt5.Qt import PYQT_VERSION_STR

if PYQT_VERSION_STR=='5.5.1': from PyQt5 import QtWebKitWidgets else: from PyQt5 import QtWebEngineWidgets

class Example(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): self.button1 = …
Run Code Online (Sandbox Code Playgroud)

python qtwebkit qtestlib pyqt5 qtwebengine

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

Selenium:Firefox Webdriver的about:config中的布尔设置

对于一个测试套件,我正在运行一个使用selenium webdriver控制Firefox实例的python脚本。我想将dom.disable_open_during_loadabout:config中的设置更改为true。尽管这是我默认的Firefox配置文件中的默认设置,但是false每当我启动Webdriver实例时,selenium都会将其更改为(用户定义)。似乎使用的是匿名的,略有更改的个人资料?!然后,我可以手动将其改回,但是我在用代码来解决这一问题:既不使用新的配置文件,也不使用通过Firefox的配置文件管理器配置的预设配置文件即可解决该问题。

from selenium import webdriver

FFprofile = webdriver.FirefoxProfile()
FFprofile.set_preference('dom.disable_open_during_load', 'true')  # I also tried True, 1 - with and without quotes
# FFprofile = webdriver.FirefoxProfile('C:/Users/ExampleUser/AppData/Local/Mozilla/Firefox/Profiles/owieroiuysd.testprofile')


FFdriver = webdriver.Firefox(firefox_profile=FFprofile)
FFdriver.get('http://www.google.com')
Run Code Online (Sandbox Code Playgroud)

我可以通过这种方式更改各种设置,但不适用于此设置。更改后的值false“用户定义”来自何处?它是硒自动设置的地方吗?我正在使用:

  • 壁虎起子0.16.1
  • 硒3.4.2。
  • Firefox 53.0.3(64位)
  • python 3.4.4

编辑:我刚刚在SO上找到了这个问题,在Java中处理了同样的问题。

如果事实证明这是不可能的,那么可能有一个不错的解决方法?有任何想法吗?

python selenium selenium-webdriver

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