如何使用 Selenium 和 Python 单击文本为(全选)的下拉项

2024-04-02

编辑:关于这个page https://i.stack.imgur.com/mdjih.png,我正在尝试提交从数据库生成的报告的参数。我已经能够为 send_keys() 发送第一个字段的新开始日期。第二个字段(结束日期)保持不变。对于第三个字段及之后的字段(除第一个字段外),我需要单击(Select All).

我需要点击(Select All),仅在单击父级“divDropDown”后才显示在隐藏的下拉表中。激活后,此隐藏表会显示一个 tbody,其中 5-6 个 tr/td/span 集保存各种选项。您可以在 id 下找到全选选项ctl31_ctl04_ctl07_divDropDown_ctl00.
在 HTML 的更上方,有一个 dropDownButton ,它不会在代码中生成错误(前 2 行),但也不会像手动那样在浏览器上显示为激活该下拉菜单,所以我认为它没有帮助这里。

我搜索了相关答案,并尝试了 Selenium 中的各种代码(等待、execute_script 等)来访问此项目,甚至尝试切换到其上方的 iframe(似乎在单击输入区域时激活,尽管寻找的元素在它之外),但仍然出现错误“无法找到元素...” 以下是尝试过的各种代码:

driver.find_element_by_xpath('//*[@id="ctl31_ctl04_ctl07"]')#.click()
driver.find_element_by_xpath('//*[@id="ctl31_ctl04_ctl07_ddDropDownButton"]').click()

#driver.find_element_by_xpath('//*[@id="ctl31_ctl04_ctl07_divDropDown"]').click()
#driver.execute_script("event.cancelBubble=true;")
#driver.execute_script("arguments[0].click();", elem)
#driver.find_element_by_xpath('//*[@id="ctl31_ctl04_ctl07_divDropDown_HiddenIndices" and @type="hidden"]')

#elem1 = driver.find_element_by_xpath('//*[@id="ctl31_ctl04_ctl07_divDropDown_ctl00" and @type="checkbox"]')#.click()
elem1 = driver.find_element_by_xpath('//*div[@id="ctl31_ctl04_ctl07_divDropDown"]/.//span[@id="ctl31_ctl04_ctl07_divDropDown_ctl00"]').get_attribute("innerHTML")
driver.execute_script("arguments[0].click();", elem1)
selector = '#ctl31_ctl04_ctl07_divDropDown_ctl00'
selector = '#ctl31_ctl04_ctl07_divDropDown > span > div:nth-child(1) > table > tbody > tr:nth-child(1) > td > span > label'
path = '//*[@id="ctl31_ctl04_ctl07_divDropDown"]/span/div[1]/table/tbody/tr[1]/td/span/input'#label'
#path = '//*[@id="ctl31_ctl04_ctl07_divDropDown_ctl00"]'
#driver.find_element_by_css_selector(selector).click()
driver.find_element_by_xpath(path).click()

我相信它无法找到元素,因为它通常是隐藏的,但无论我如何尝试单击或执行下拉菜单,通过按钮或单击 div,它都不会保持打开状态(我有时会看到它闪烁,它只是重新关闭,因此表格及其下拉列表再次隐藏)。我还尝试了以下代码来测试它。使用常规等待命令,经过一些迭代后我会收到“陈旧元素”错误。没有任何等待,我就会得到 element not find 。通过“等到”,我可以看到下拉列表向上/向下移动,但当它可见时似乎无法捕获“全选”?所有这一切都是用我的打印语句打开/关闭下拉列表以查看何时(在打印“检查是否存在”之后)。我也尝试过直接执行“全选脚本”"$get('ctl31_ctl04_ctl07').control.OnSelectAllClick(this);"无济于事。

def check_exists_by_xpath(xpath):
    try:
        driver.find_element_by_xpath(xpath)
    except NoSuchElementException:
        return False
    return True

for i in range(15):
    #driver.implicitly_wait(1000)
    #driver.find_element_by_xpath('//*[@id="ctl31_ctl04_ctl07_ddDropDownButton"]').click()
    wait(driver, 1000).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="ctl31_ctl04_ctl07_ddDropDownButton"]'))).click()
    #elem = driver.find_element_by_xpath('//*[@id="ctl31_ctl04_ctl07_divDropDown_ctl00"]')
    print('checking if exists')
    if check_exists_by_xpath('//*[@id="ctl31_ctl04_ctl07_divDropDown_ctl00"]'):
        driver.find_element_by_xpath('//*[@id="ctl31_ctl04_ctl07_divDropDown_ctl00"]').click()
        print('did it!')
    else: print('past dropdown button %d' % i)
    i +=1

这是 HTML(这是一个登录网站,所以我不能显示太多其他内容,抱歉图片:html https://i.stack.imgur.com/FDuAs.png

<iframe id="ctl31_ctl04_ctl07_ctl01" onclick="event.cancelBubble=true;" onactivate="event.cancelBubble=true;" style="display:none;position:absolute;z-index:10;" src="javascript:'';" frameBorder="0" title="Borough: place holder" longdesc="Borough: place holder" Name="ctl31_ctl04_ctl07_ctl01"></iframe>
<div id="ctl31_ctl04_ctl07_divDropDown" onclick="event.cancelBubble=true;" onactivate="event.cancelBubble=true;" style="display:inline-block;border-color:DarkGray;border-width:1px;border-style:Solid;overflow:auto;background-color:window;display:none;position:absolute;z-index:11;">
    <span style="margin: 0px; background-color: window;"><div style="overflow: auto; width: 186px; height: 133px;">
            <table cellpadding="0" cellspacing="0" style="background-color:window;">
                <tbody>
                    <tr>
                        <td nowrap="nowrap">
                            <span>
                                <input id="ctl31_ctl04_ctl07_divDropDown_ctl00" type="checkbox" name="ctl31$ctl04$ctl07$divDropDown$ctl00" onclick="$get('ctl31_ctl04_ctl07').control.OnSelectAllClick(this);"><label for="ctl31_ctl04_ctl07_divDropDown_ctl00">(Select All)</label>
                            </span></td></tr>
                    <tr>
                        <td nowrap="nowrap"><span><input id="ctl31_ctl04_ctl07_divDropDown_ctl01" type="checkbox" name="ctl31$ctl04$ctl07$divDropDown$ctl01" onclick="$get('ctl31_ctl04_ctl07').control.OnValidValueClick(this, 'ctl31_ctl04_ctl07_divDropDown_ctl00');"><label for="ctl31_ctl04_ctl07_divDropDown_ctl01">MANHATTAN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label></span></td></tr>
                    <tr>
                        <td nowrap="nowrap"><span><input id="ctl31_ctl04_ctl07_divDropDown_ctl02" type="checkbox" name="ctl31$ctl04$ctl07$divDropDown$ctl02" onclick="$get('ctl31_ctl04_ctl07').control.OnValidValueClick(this, 'ctl31_ctl04_ctl07_divDropDown_ctl00');"><label for="ctl31_ctl04_ctl07_divDropDown_ctl02">BROOKLYN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb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nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label></span></td></tr>
                    <tr>
                        <td nowrap="nowrap"><span><input id="ctl31_ctl04_ctl07_divDropDown_ctl03" type="checkbox" name="ctl31$ctl04$ctl07$divDropDown$ctl03" onclick="$get('ctl31_ctl04_ctl07').control.OnValidValueClick(this, 'ctl31_ctl04_ctl07_divDropDown_ctl00');"><label for="ctl31_ctl04_ctl07_divDropDown_ctl03">QUEENS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label></span></td></tr>
                    <tr>
                        <td nowrap="nowrap"><span><input id="ctl31_ctl04_ctl07_divDropDown_ctl04" type="checkbox" name="ctl31$ctl04$ctl07$divDropDown$ctl04" onclick="$get('ctl31_ctl04_ctl07').control.OnValidValueClick(this, 'ctl31_ctl04_ctl07_divDropDown_ctl00');"><label for="ctl31_ctl04_ctl07_divDropDown_ctl04">BRONX&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label></span></td></tr>
                    <tr>
                        <td nowrap="nowrap"><span><input id="ctl31_ctl04_ctl07_divDropDown_ctl05" type="checkbox" name="ctl31$ctl04$ctl07$divDropDown$ctl05" onclick="$get('ctl31_ctl04_ctl07').control.OnValidValueClick(this, 'ctl31_ctl04_ctl07_divDropDown_ctl00');"><label for="ctl31_ctl04_ctl07_divDropDown_ctl05">STATEN&nbsp;ISLAND&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs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r>
                </tbody>
            </table>
            <input type="hidden" name="ctl31$ctl04$ctl07$divDropDown$HiddenIndices" id="ctl31_ctl04_ctl07_divDropDown_HiddenIndices" value="">
        </div>
        <div style="height: 16px; width: 100%; margin: 0px; border-top: 1px solid lightgray; background-color: window; direction: ltr;"></div>
    </span>
</div>


网页如下所示:page https://i.stack.imgur.com/mdjih.png

有任何想法吗?


单击文本为的下拉选项(全选)因为元素是JavaScript https://www.javascript.com/您需要诱导的启用元素WebDriver等待为了想要的元素可点击您可以使用以下解决方案:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[contains(@id, '_divDropDown') and contains(@onclick, 'cancelBubble')][contains(@onactivate, 'cancelBubble')]"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[contains(@id, '_divDropDown') and contains(@onclick, 'cancelBubble')][contains(@onactivate, 'cancelBubble')]/span/div/table/tbody/tr/td/span//label[contains(@for, '_divDropDown_') and contains(., '(Select All)')]"))).click()

Note:您必须添加以下导入:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用 Selenium 和 Python 单击文本为(全选)的下拉项 的相关文章

  • feedparser 在脚本运行期间失败,但无法在交互式 python 控制台中重现

    当我运行 eclipse 或在 iPython 中运行脚本时 它失败了 ascii codec can t decode byte 0xe2 in position 32 ordinal not in range 128 我不知道为什么 但
  • python 集合可以包含的值的数量是否有限制?

    我正在尝试使用 python 设置作为 mysql 表中 ids 的过滤器 python集存储了所有要过滤的id 现在大约有30000个 这个数字会随着时间的推移慢慢增长 我担心python集的最大容量 它可以包含的元素数量有限制吗 您最大
  • 如何正确取消引用然后删除 JavaScript 对象?

    我想知道从内存中完全取消引用 JavaScript 对象的正确方法 确保删除时不会在内存中悬空 并且垃圾收集器会删除该对象 当我看这个问题时在 JavaScript 中删除对象 https stackoverflow com questio
  • 改变 JavaScript 中的顶部填充

    以下是我在 css 中设置顶部填充的方法 body font size font size px margin 0 padding 100px 0 20px 0 width 100 important 如何使用最简单的 javascript
  • 如何将 numpy.matrix 提高到非整数幂?

    The 运算符为numpy matrix不支持非整数幂 gt gt gt m matrix 1 0 0 5 0 5 gt gt gt m 2 5 TypeError exponent must be an integer 我想要的是 oct
  • JavaScript eval("{}") 返回行为?

    根据ECMA 262 规范 http www ecma international org publications files ECMA ST Ecma 262 pdf 以下语句返回1 eval 1 eval 1 eval 1 var a
  • 如何从浏览器向服务器发送“页面将关闭”消息?

    我想向每个 html 文档添加一个脚本 JavaScript 该脚本向服务器发送两条消息 页面确实打开了 页面将关闭 此消息包含页面打开的时间 打开消息应在文档加载时 或加载完成时 发送 这是简单的部分 The close message
  • Rails 3.1+ 的 Jasmine 与 Mocha JavaScript 测试 [已关闭]

    Closed 这个问题是基于意见的 help closed questions 目前不接受答案 我对茉莉花有经验并且非常喜欢它 有谁有 Jasmine 和 Mocha 的经验 特别是 Rails 的经验吗 我想知道是否值得转用 我已经在 J
  • 从 pygame 获取 numpy 数组

    我想通过 python 访问我的网络摄像头 不幸的是 由于网络摄像头的原因 openCV 无法工作 Pygame camera 使用以下代码就像魅力一样 from pygame import camera display camera in
  • 在Python中重置生成器对象

    我有一个由多个yield 返回的生成器对象 准备调用该生成器是相当耗时的操作 这就是为什么我想多次重复使用生成器 y FunctionWithYield for x in y print x here must be something t
  • Highcharts jQuery 渲染问题 - 所有浏览器

    我在尝试使用构建堆积柱形图时遇到了一个奇怪的问题高图表 http www highcharts com 当图表呈现时 在您调整浏览器大小之前 不会显示列无论如何 导致图表重绘 我认为 图表的其余部分显示 轴 标题等 但不显示列本身 我在 I
  • VSCode:调试配置中的 Python 路径无效

    对 Python 和 VSCode 以及 stackoverflow 非常陌生 直到最近 我已经使用了大约 3 个月 一切都很好 当尝试在调试器中运行任何基本的 Python 程序时 弹出窗口The Python path in your
  • 如何从没有结尾的管道中读取 python 中的 stdin

    当管道来自 打开 时 不知道正确的名称 我无法从 python 中的标准输入或管道读取数据 文件 我有作为例子管道测试 py import sys import time k 0 try for line in sys stdin k k
  • 如何使用google colab在jupyter笔记本中显示GIF?

    我正在使用 google colab 想嵌入一个 gif 有谁知道如何做到这一点 我正在使用下面的代码 它并没有在笔记本中为 gif 制作动画 我希望笔记本是交互式的 这样人们就可以看到代码的动画效果 而无需运行它 我发现很多方法在 Goo
  • 循环标记时出现“ValueError:无法识别的标记样式 -d”

    我正在尝试编码pyplot允许不同标记样式的绘图 这些图是循环生成的 标记是从列表中选取的 为了演示目的 我还提供了一个颜色列表 版本是Python 2 7 9 IPython 3 0 0 matplotlib 1 4 3 这是一个简单的代
  • 在 Python 类中动态定义实例字段

    我是 Python 新手 主要从事 Java 编程 我目前正在思考Python中的类是如何实例化的 我明白那个 init 就像Java中的构造函数 然而 有时 python 类没有 init 方法 在这种情况下我假设有一个默认构造函数 就像
  • Python - 字典和列表相交

    给定以下数据结构 找出这两种数据结构共有的交集键的最有效方法是什么 dict1 2A 3A 4B list1 2A 4B Expected output 2A 4B 如果这也能产生更快的输出 我可以将列表 不是 dict1 组织到任何其他数
  • 将数组从 jquery ajax 传递到代码后面

    我必须将二维数组传递给在asp net网页代码后面编写的页面方法我有一个变量objList作为二维数组 我使用以下代码来实现此目的 但没有成功 并且未调用页面方法 脚本语言 function BindTable objList ajax u
  • 测量窗口偏移

    有没有一种方法可以测量 jQuery 中窗口的偏移量 以便我可以比较 固定 元素和相对定位元素的位置 我需要能够知道窗口滚动了多远 以便我可以使用该图来计算固定元素的高度 相对于视口顶部 和相对对象的高度 相对于顶部 之间的差异文件的内容
  • 使用velocity.js制作可拖动元素的动画

    我正在使用velocity js 为用户拖动的可拖动 SVG 元素设置动画 然而 velocity js 将先前的 mousemove 坐标排队并通过所有后续的 mousemove 坐标进行动画处理 我想要的是velocity js 不要对

随机推荐

  • Qt 忽略 makefile、.pro.user 文件

    我开发基于 Qt 的项目并使用 Mercurial 存储库 bitbucket org 服务 进行版本控制 每次我在存储库中提交时 都会有一些文件仅包含标头中的日期时间更改 因此 每次提交我都应该检查每个文件是否有重大更改 而不仅仅是时间戳
  • Mongoose / MongoDB - 在一条指令中更新具有不同 _id 和值的多个文档

    我正在寻找一种在一条指令中更新多个 MongoDB 文档的方法 我知道有一个 updateMany 查询 但它需要严格的过滤参数才能更新多个文档 我有一组想要更新的对象 如下所示 const objectsToUpdate id 1 fie
  • Angular 6:如何访问 mat-autocomplete 下拉列表中的所有选项值?

    给出 Angular 文档中的示例你可以在这里看到 https material angular io components autocomplete overview setting separate control and displa
  • 对仅包含 a-z 和空格的单词数组进行排序的最快方法是什么?

    我想知道是否有比快速排序 合并排序更快的方法来对此类数组进行排序 数组的最大长度为 10 6 单词的长度 gt 10 且 您可以将所有单词放在一个trie http en wikipedia org wiki Trie or a 基数树 h
  • 缺少值组合的完整数据框

    我有一个包含两个因素的数据框 distance 和年份 years 我想完成所有years每个因子的值均除以 0 即由此而来 distance years area 1 NPR 3 10 2 NPR 4 20 3 NPR 7 30 4 10
  • 如何清除Java 9 JShell控制台?

    我没有找到任何清除 Java 9 JShell 控制台的命令 我也尝试通过这个程序清除JShell控制台 但它也不起作用 import java io IOException class CLS public static void mai
  • Android - 如何从 kotlin 流中读取值?

    我有来自房间数据库的剧集流程 我可以毫无问题地观察该流程的实时数据 但我还想在用户单击按钮时读取此流程中的最后一个值 我尝试使用first 终端流运算符 但它无法编译 您能帮忙或提出其他建议吗 非编译尝试从流中读取 bd buttonNex
  • 将上下文传递给自定义挂钩或在自定义挂钩内调用 useContext 更好吗?

    我有越来越多的自定义挂钩 其中许多通过以下方式访问相同的反应上下文useContext钩 在许多组件中 需要使用多个自定义挂钩 打电话比较好吗useContext每个组件一次并将上下文传递到我的自定义挂钩中 还是最好调用useContext
  • 如何删除/取消注册 GitLab 运行程序

    几个月前我注册了一个个人 GitLab 运行器 但我不再使用它 如何完全删除它 使其不会显示在我的 GitLab CI CD 设置页面上 列出跑步者以获取他们的令牌和 URL sudo gitlab runner list 使用指定运行者令
  • Android 10.0 应用程序在 BOOT 上启动

    我们有一个 Android 应用程序 我们打算在手机启动期间启动 启动 通过在 Android 10 中尝试一些代码 我们意识到在 Android 8 0 之后无法在启动时启动应用程序 以前在 Android 6 中 这是可能的 即使在物理
  • Heroku Dynos 是否享受 AWS 网络内的免费数据传输?

    我正在考虑将 Heroku 用于 NodeJS 应用程序 我想知道他们的 Dynos 是否享受 AWS 网络内的免费内部数据传输 我想使用 DynamoDB ElastiCache RDS SQS 和许多其他 AWS 产品 如果我可以从 H
  • 如何使用 OpenXML 查找段落中的页码?

    For a 段落对象 如何使用 Open XML SDK 2 0 for Microsoft Office 确定该对象位于哪个页面 使用以下方法无法获取 Word 文档的页码OpanXml Sdk因为这是由客户端处理的 例如 MS Word
  • 推送 UIView 时隐藏 UITabBar

    我有一个UITabBarController其中默认视图控制器是UINavigationController 当我在视图中推送某个视图时 我希望能够隐藏 UITabBarController 的 UITabBarUINavigationCo
  • 如何获取任务的结果或返回值?

    有人可以向我解释如何返回任务的结果吗 我目前正在尝试执行以下操作 但我的任务没有返回我期望的列表 这里有什么问题 static void Main List
  • 无法读取 null 的属性“props” - Reactjs [重复]

    这个问题在这里已经有答案了 基本上我想在子组件中调用父组件的函数 该函数将更改父组件的状态 我在父组件中创建了一个处理程序并将其作为道具传递给子组件 现在我想在子组件中调用它 Parent state formstep 1 construc
  • 如何覆盖 laravel 资源路由默认方法?

    我的 REST API url 具有以下架构 Verb Url Method GET tasks findAll GET tasks id findOne POST tasks create PUT tasks id update DELE
  • 读取行期间的 Source.fromInputStream 异常处理

    我创建了一个函数 其中接受输入流作为参数并返回由字符串组成的迭代器 我按如下方式完成此操作 def lineEntry fileInputStream InputStream Iterator String Source fromInput
  • Common Lisp 中的(随机)不那么随机?

    好的 最后一个问题 我将用 Common Lisp 完成我的猜数游戏 D 每当游戏开始 或者在第一个游戏之后开始新游戏 时 都会调用以下函数 Play the game defun play If it s their first time
  • Symfony v4、php bin/console 无法按预期工作。自动中止[重复]

    这个问题在这里已经有答案了 我刚刚在我的新 SSD 上安装了 Composer php apache 等 之后我想开始编码 我从 IDE 中的另一个驱动器打开了我的项目 然后我想将我的灯具加载到我的新数据库中 但我不能 我什至无法进行迁移等
  • 如何使用 Selenium 和 Python 单击文本为(全选)的下拉项

    编辑 关于这个page https i stack imgur com mdjih png 我正在尝试提交从数据库生成的报告的参数 我已经能够为 send keys 发送第一个字段的新开始日期 第二个字段 结束日期 保持不变 对于第三个字段