我必须使用下面给出的Selenium Webdriver执行以下任务.
任何人都可以共享,我们如何使用Java实现这一点?
好到目前为止,我有我的编程去网站我想下载链接并选择它,然后firefox对话框出现,我不知道该怎么办.我想将此文件保存到桌面上的文件夹中.我正在使用它进行夜间构建,所以我需要这个工作.请帮忙.
这是我从网站上获取下载链接的代码:
driver = web driver.Firefox()
driver.implicitly_wait(5)
driver.get("Name of web site I'm grabbing from")
driver.find_element_by_xpath("//a[contains(text(), 'DEV.tgz')]".click()
Run Code Online (Sandbox Code Playgroud) 我想自动下载文件并将它们保存在目录中,一切都已完成,但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) 我正在使用selenium webdriver使用firefox进行一些下载.目前,我的脚本在下载启动后等待特定时间,然后关闭Firefox.我想知道是否有办法配置firefox自动关闭下载完成?或者使用selenium webdriver,我可以检查下载是否已完成?我不想使用任何添加,因为它可能会在我的脚本中添加依赖项.我不能使用wget/curl等来下载文件.提前致谢
我正在尝试使用 Selenium Chrome 网络驱动程序下载文件,但我不知道如何处理另存为对话框。
我已经看到很多关于如何使用 Firefox 执行此操作的答案,但没有使用 Chrome。
我正在尝试在python中使用Selenium模块从一个网站生成文本列表,将其保存在目录中,然后浏览到另一个站点上的该文本列表以提交它.
我正在分两部分编写脚本 - 1.获取元数据和2.订购数据.我已经成功完成了第1部分中的脚本,除了最后一件事:选择保存刚刚生成的元数据文件.我把它留在第2部分工作,希望我会偶然发现答案,但是当选择文件的弹出框出现时我只是遇到同样的问题.
在文档中,我被告知Selenium WebDriver内置支持处理弹出对话框,并且在触发对话框之后,如果我调用alert = driver.switch_to_alert()
那么我可以"接受,关闭,读取其内容,甚至输入提示".
但是,它不起作用.当我尝试alert.text('some text')
或alert.send_keys(Keys.TAB)
,我不断得到错误,NoAlertPresentException: Message: No alert is present
并在添加命令等待后,我得到错误TimeoutException: Message:
我得到的弹出窗口(连接截图)是否被Selenium识别?如果是这样,我该如何与他们互动?似乎使用它来保存和/或上传文件是许多人必须要做的事情,但我在谷歌上找不到任何东西.具体来说,我想为第一张图片选择"保存文件",然后选择"确定",第二张图片我想浏览文件(即输入文件名字段的路径),然后点击"打开".我不想只是将我的Firefox设置更改为自动保存,因为这最终将在不同的环境中运行,这无助于解决我的第二个问题.
谢谢!
编辑:我正在Windows上测试我的脚本,但它最终将在Linux云服务器上实现.我以为我将不得不切换到PhantomJS webdriver(这可能会让我的问题变得更糟)去做无头浏览,但我找到了一种方法来保持Firefox.我想这一切都意味着我无法使用AutoIT来解决我的问题.
I want to download a PDF which is from an Online-Magazin. In order to open it, must log in first. Then open the PDF and download it.
The following is my code. It can login to the page and the PDF can also be open. But the PDF can not be downloaded since I am not sure how to simulate the click on Save. I use FireFox.
import os, time
from selenium import webdriver
from bs4 import BeautifulSoup
# Use …
Run Code Online (Sandbox Code Playgroud) 假设我想在这里下载数据:http://www.dce.com.cn/publicweb/quotesdata/memberDealPosiQuotes.html
我想使用python自动执行此操作,我可以在其中指定日期等.
我在这里发现可以使用pandas pd.read_csv
从网页上读取数据,但首先需要获得正确的网址.但在我的情况下,我不知道网址是什么.
此外,我还想自己指定日期和合同等.
在询问之前,我实际上尝试了开发工具,我仍然看不到网址,而且我不知道如何使其编程.
selenium ×7
python ×5
firefox ×4
csv ×1
download ×1
html ×1
javascript ×1
pandas ×1
python-3.x ×1
webdriver ×1