将 Google Chrome 更新到版本 71 后,--force-device-scale-factor 小于 1 (--force-device-scale-factor=0.5) 已停止工作。
有谁知道如何解决它,或者您有其他选择吗?
我已经成功地使用上面的脚本打印和下载了 pdf,但是我在如何在 LANDSCAPE 模式输出中使用 selenium python 打印/下载 pdf 时遇到了问题。
我尝试将 pdfkit 与“fromstring”和硒“driver.getsource”一起使用,但纵向模式效果不佳,最后我选择使用来自 chromedriver 的打印 PDF 并成功制作了我想要的 PDF 文件,但效果很好只停留在纵向模式。即使我需要的是横向模式
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
import time
import pdfkit
import json
import os
curr_dir = os.getcwd()
download_path = os.path.join(curr_dir, 'dl')
appState = {
"recentDestinations": [
{
"id": "Save as PDF",
"origin": "local"
}
],
"selectedDestinationId": "Save as PDF",
"version": 2,
}
profile = {
'printing.print_preview_sticky_settings.appState': json.dumps(appState),
'savefile.default_directory': download_path,
}
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option('prefs', profile)
chrome_options.add_argument('--kiosk-printing') …
Run Code Online (Sandbox Code Playgroud) 我已经开始使用react-hooks
并且有一些我想了解的东西。我有这个useEffect
钩子,我正在分离useEffect
钩子,我想知道每个钩子何时运行。
function MyComp(props) {
useEffect(
() => {
fetchSomeData(props.filters)
},[props.filters]
)
return (
<div>will show my data here</div>
)
}
Run Code Online (Sandbox Code Playgroud)
此挂钩是否仅在props.filters
更改后才运行?
还是我必须使用prevProps
检查它是否已更改?
像这样:
function MyComp(props) {
const prevProps = useRef(props);
useEffect(
() => {
if (prevProps.filters !== props.filters) {
fetchSomeData(props.filters)
}
},[props.filters]
)
return (
<div>will show my data here</div>
)
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Selenium来保存网页.单击某些复选框后,网页内容将发生变化.我想要的是单击一个复选框,然后保存页面内容.(复选框由JavaScript控制.)
首先我用过:
driver.find_element_by_name("keywords_here").click()
Run Code Online (Sandbox Code Playgroud)
它以错误结束:
NoSuchElementException
Run Code Online (Sandbox Code Playgroud)
然后我尝试使用"xpath",使用隐式/显式等待:
URL = “the url”
verificationErrors = []
accept_next_alert = True
aaa = driver.get(URL)
driver.maximize_window()
WebDriverWait(driver, 10)
#driver.find_element_by_xpath(".//*[contains(text(), ' keywords_here')]").click()
#Or:
driver.find_element_by_xpath("//label[contains(text(),' keywords_here')]/../input[@type='checkbox']").click()
Run Code Online (Sandbox Code Playgroud)
它给出了一个错误:
ElementNotVisibleException
Run Code Online (Sandbox Code Playgroud)
帖子
如何强制Selenium WebDriver点击当前不可见的元素?
建议它应该在点击之前使复选框可见,例如使用:
execute_script
Run Code Online (Sandbox Code Playgroud)
这个问题可能听起来很愚蠢,但是如何从页面源代码中找到"execute_script"复选框可见性的正确句子?
除此之外,还有另一种方式吗?
谢谢.
顺便说一句,行html代码看起来像:
<input type="checkbox" onclick="ComponentArt_HandleCheck(this,'p3',11);" name="keywords_here">
Run Code Online (Sandbox Code Playgroud)
它的xpath看起来像:
//*[@id="TreeView1_item_11"]/tbody/tr/td[3]/input
Run Code Online (Sandbox Code Playgroud) javascript python selenium selenium-webdriver execute-script
这是我的服务器端代码:
app.set('view engine', 'html');
app.engine('html', require('ejs').renderFile);
app.use(express.static('views'));
app.use(bodyParser.urlencoded({extended:true}));
app.use(bodyParser.json());
app.get('/',function(req,res){
var title = "PERFORMANCE OVERVIEW";
res.render('Main.html',{name:title});
})
Run Code Online (Sandbox Code Playgroud)
这是我的客户端代码(Main.html):
<div class="row">
<div class="sm-col-12">
<h3 contenteditable="true" style="font-family:BentonSans Medium; text-align:center; color:rgb(0,38,99);"><%= name %></h3>
<hr style="border-top: dotted 2px;color:grey" />
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我在 Main.html 页面上得到的输出是“<%-name%>”。相反,它应该打印“性能概述”。这段代码究竟有什么问题?
编辑:
我忘了提到我还尝试了其他变体,例如<%= name%> and {{ name }}
. 但我"<%= name%>" and "{{ name }}"
分别得到了输出。
我创建了一个如下项目:
project
|
| --package1
| |
| -- __init__py
| --module1.py
|
| --package2
|
--__init__.py
--module2.py
Run Code Online (Sandbox Code Playgroud)
我想将 module1 导入到 module2 中,(from package1 import module1)
在 PyCharm 中一切都工作正常。但是当我尝试从 Windows10 命令提示符打开文件“module2.py”时,我得到了 ModuleNotFoundError: No module named 'module1'
.
我一直在寻找解决方案,但没有一个有效。我正在使用 python 3.6 并且我已经设置了环境变量PYTHONPATH = I:\project\package1
python ×3
selenium ×3
javascript ×2
ejs ×1
express ×1
html ×1
landscape ×1
node.js ×1
printing ×1
python-3.x ×1
react-hooks ×1
react-props ×1
reactjs ×1
teamcity ×1
windows ×1