- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
堆栈:Windows 8.1、Python 3.4.3.4、Selenium 2.46、Chromedriver 2.16
我使用 Selenium Python 与 Chromedriver 绑定(bind)来自动从以下 URL 进行一些下载:r'http://financials.morningstar.com/'
我设置了以下 chromedriver 首选项:
chromeOptions = webdriver.ChromeOptions()
prefs = {'download.default_directory':symbol_dir}
chromeOptions.add_experimental_option('prefs', prefs)
chromeOptions.add_extension(self.chromeUBlock_path)
chromedriver_path = self.chromedriver_path
此外,我还设置了以下 Selenium 代码来运行下载,该下载可以正常工作并下载到正确的文件位置等:
symbol = 'AAPL' # test symbol
IS_anl_statement = 'income-statement'
IS_anl_abbrev = 'is'
url_anl = self.mstar_base_url + r'{}/{}.html?t={}®ion=usa&culture=en-US'
IS_anl = webdriver.Chrome(executable_path=chromedriver_path, chrome_options=chromeOptions)
IS_anl.set_page_load_timeout(90)
try:
IS_anl.get(url_anl.format(IS_anl_statement, IS_anl_abbrev, symbol))
anl_element = WebDriverWait(IS_anl, 90).until(EC.element_to_be_clickable(
(By.LINK_TEXT, 'Annual')))
anl_csv_element = WebDriverWait(IS_anl, 90).until(EC.element_to_be_clickable(
(By.CSS_SELECTOR,self.css_path_export)))
anl_csv_element.click()
for i in range(1,10,1):
time.sleep(i/50)
if os.path.isfile(anl_file_string)==True:
break
except Exception as e:
print(e)
IS_anl.quit()
但是,当使用以下缩写运行下载时(只需将 balance-sheet
替换为 profit-statement
,如下所示:
BS_anl_statement = 'balance-sheet'
BS_anl_abbrev = 'bs'
和其余的 Selenium 代码完全相同,我得到了可怕的下载错误:失败路径太长
这很奇怪,因为实际的文件路径不太长。事实上,我在 3 个不同的目录中测试了下载,每个目录的文件路径都比上一个更短。最终示例路径为:r"C:\mstar_data\\"
我被困住了。我在两次下载尝试之间看到的唯一区别是实际的 CSV
链接。但即使在这种情况下,损益表
下载网址实际上也比 Assets 负债表
长,所以我再次陷入困境。它们在这里:
I/S CSV 网址:http://financials.morningstar.com/ajax/ReportProcess4CSV.html?&t=XNAS:ZUMZ®ion=usa&culture=en-US&cur=&reportType=is&period=12&dataType=A&order=asc&columnYear=5&curYearPart=1st5year&rounding=3&view=raw&r=573205&deminatorView =原始&数字=3
B/S CSV 网址:http://financials.morningstar.com/ajax/ReportProcess4CSV.html?&t=XNYS:A®ion=usa&culture=en-US&cur=&reportType=bs&period=12&dataType=A&order=asc&columnYear=5&curYearPart=1st5year&rounding=3&view=raw&r=558981&deminatorView =原始&数字=3
对这种不一致的任何帮助都将是一个很大的帮助,并且绝对值得赞赏。谢谢。
最佳答案
我找到了解决此问题的方法。 @Skandigraun 是对的,有一段代码试图过早地使用下载的文件。
我使用高级卸载程序
清除了所有临时文件、互联网历史记录等。我重新启动了电脑。我更改了以下有关 Skandigraun 评论的代码块:
for in range(1, 10, 1):
time.sleep(i/50)
if os.path.isfile(anl_file_string)==True:
break
至:
for i in range(1, 10, 1):
time.sleep(i/20) # changed from 50 to 20
if os.path.isfile(anl_file_string)==True:
break
我补充道:
finally:
IS_anl.quit()
现在代码运行更加稳定。我相信测试文件是否存在的操作系统调用发生得太快/太频繁,导致下载失败。我将 finally
语句添加到 try/except
循环中,以关闭浏览器,无论发生什么情况。如果访问站点出现问题、超时错误等,这可以防止脚本挂起。
关于python - 使用Python Selenium Chromedriver下载不一致 'Failed - Path too long'错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31630613/
Selenium IDE、Selenium RC 和 Selenium WebDriver 有什么区别;我们可以在什么样的项目中使用它们?任何建议将不胜感激。 最佳答案 Selenium IDE 是一
我的 Selenium 服务器在远程服务器上运行。我从我的本地 PC 启动我的 Selenium 脚本,它从网站获取数据。 例如,我的 Selenium 脚本执行这段 JS 代码: JSON.stri
Selenium 中“//div[.//a[text()='SELENIUM']]”和“//div[//a[text()='SELENIUM']]”有什么区别xpath。 有人可以澄清我在 xpath
我正在创建自动冒烟测试。我读到在单元测试中使用多个断言不是一个好的做法,这条规则是否也适用于使用 selenium 的 webdriver 测试? 在我的冒烟测试中,有时我会使用 20 多个断言来验证
我在一个变量中存储了一个值,在另一个变量中存储了第二个值,现在我想将这两个数字相加。我无法做到这一点,我尝试过下面的代码,但它不起作用 store 6 w sto
Selenium 中的回车键和回车键有什么区别? This related SO answer并且提供的链接说明它们是不同的。我还注意到,在使用 Firefox 24.2 时,回车键将发送一个 HTM
以下是我遇到异常的详细信息: 当我使用以下命令启动节点时,出现如下错误: F:\SeleniumGrid\Jars>java -jar selenium-server-standalone-3.0.0
我是 的新手 Selenium 我对版本号有点困惑。 Selenium 2.0 2011年发布。我刚刚下载了 Selenium IDE Firefox 扩展,版本为 1.7.2 .是否还有 IDE 的
我正在使用 Selenium 运行Codeception 2。我可以看到 Selenium 打开了浏览器并运行了测试。然后,我从代码接收中得到一个错误,即存在失败的断言。 我知道有一个HTML文件可以
Closed. This question needs to be more focused。它当前不接受答案。 想要改善这个问题吗?更新问题,使它仅关注editing this post的一个问题。
我想关闭弹出窗口(已知的窗口名称),然后返回到原始窗口。 我该怎么办? 如果我无法获得窗口中关闭按钮的常量。那么有没有达到目标的一般行为? 最佳答案 你有没有尝试过: selenium.Close()
我正在用webdriver做一个测试机器人。我有一个场景,它单击一个按钮,打开一个新窗口,并且它通过特定的xpath搜索元素,但是有时没有这样的元素,因为可以将其禁用,并且出现此错误:org.open
我是第一次使用Selenium,对这些选项不知所措。我在Firefox中使用IDE。 当我的页面加载时,它随后通过JSONP请求获取值,并在其中填充选择中的选项。 我如何让Selenium等待选择中的
我开始使用nightwatch.js编写e2e测试,我注意到我想在目标浏览器的控制台(开发人员工具)中手动检查一些错误。但总是在我打开开发者控制台时,浏览器会自动关闭它。这是selenium还是nig
我正在尝试使用以下方式刮除Glassdoor的评论: https://github.com/MatthewChatham/glassdoor-review-scraper 但是我得到了错误并且不知道如
背景 我设置了一个Selenium Grid项目,以在两种不同的浏览器Chrome和Firefox中执行测试。我正在使用Gradle执行测试。该测试将成功执行两次,一次按预期在Chrome中执行,一次
当测试失败时,运行 selenium 测试的浏览器将关闭。这在尝试调试时没有帮助。我知道我可以在失败时选择屏幕截图,但如果没有整个上下文,这并没有帮助。在浏览器仍然可用的情况下,我可以回击并检查发生了
使用 Selenium Web 驱动程序而不是 Selenium RC 启动新的测试框架是个好主意吗?对于 Selenium Web 驱动程序,并非所有 Selenium 方法都已实现。那么使用 Se
我使用 selenium 页面对象模型来定义所有页面元素。我对元素命名所遵循的命名约定不太相信,并且感觉太长了。请对此提出建议。 @FindBy(xpath = "//tbody[@id='tabvi
有一个带有按钮的 html 页面,我的 Selenium 测试正在测试,当单击按钮时,会执行一个操作。 问题是,看起来点击发生在 javascript 执行之前 - 在处理程序绑定(bind)到页面之
我是一名优秀的程序员,十分优秀!