网站后台怎么换图片做百度竞价网站搜索不到
- 作者: 五速梦信息网
- 时间: 2026年03月21日 07:55
当前位置: 首页 > news >正文
网站后台怎么换图片,做百度竞价网站搜索不到,建设黑彩网站,如何建一个自己的网站前几天在使用Selenium进行元素拖拽操作时#xff0c;发现Selenium自带的元素拖拽方法#xff08;dragAndDrop()#xff09;不生效#xff0c;网上的回答也是五花八门#xff0c;比较混乱#xff0c;尝试了以下几种方法均无法解决。 方案1#xff1a;通过dragAndDrop()方…前几天在使用Selenium进行元素拖拽操作时发现Selenium自带的元素拖拽方法dragAndDrop()不生效网上的回答也是五花八门比较混乱尝试了以下几种方法均无法解决。 方案1通过dragAndDrop()方法将元素拖放到特定区域上——无效。 // 要拖拽的元素WebElement draggable driver.findElement(By.xpath());// 目标元素/区域WebElement droppable driver.findElement(By.xpath());new Actions(driver).dragAndDrop(draggable, droppable).build().perform();方案2通过dragAndDropBy()方法将元素进行指定像素位移从而实现拖放到特定区域该方法需要先找到元素的像素——无效。 new Actions(driver).dragAndDropBy(draggable,135, 40).build().perform();方案3先通过clickAndHold()方法点击并按住元素然后使用moveByOffset()方法将元素拖拽到目标区域再使用release()方法将按住的元素释放——无效。 new Actions(driver).clickAndHold(draggable).moveByOffset(400, 0).release().build().perform();方案4先通过clickAndHold()方法点击并按住元素然后使用moveToElement()方法将元素拖拽到指定元素上再使用release()方法将元素释放——无效。 new Actions(driver).clickAndHold(draggable).moveToElement(droppable).release(droppable).build().perform();方案5借助Robot类实现拖拽——无效。 Point coordinates1 draggable.getLocation();Point coordinates2 droppable.getLocation();Robot robot new Robot();robot.mouseMove(coordinates1.getX(), coordinates1.getY());robot.mousePress(InputEvent.BUTTON1_MASK);robot.mouseMove(coordinates2.getX(), coordinates2.getY());robot.mouseRelease(InputEvent.BUTTON1_MASK);……以上方案均未生效具体表现为运行均无任何报错但在应用程序中未发生拖放。 经过一顿操作最终在「Selenium Drag and Drop Bug Workaround」上找到了问题原因及解决方案。 经了解Selenium的拖放功能在某些情况下无效的错误已经存在多年。 原因是拖放功能包含三个动作单击并按住click and hold、将鼠标移动到其他元素或位置move mouse to other element/location、释放鼠标release mouse问题在于最后一步释放鼠标的操作当Webdriver API发送释放鼠标的请求时在某些情况下它会一直按住它所以导致拖放功能无效。 解决方法就是通过Webdriver API将JavaScript代码发送到浏览器利用JavaScript模拟拖放操作而不使用Webdriver自带的拖放方法。 其工作原理是将浏览器实例和CSS选择器找到的两个Web元素作为参数然后在浏览器端执行JavaScript代码。 如果你是使用PythonSelenium技术栈实现的Web UI自动化可以直接下载seletoolsSelenium Tools作者Dmitrii Bormotov包并将它导入到需要执行拖放的地方然后简单地调用它的drag_and_drop()方法即可。 pip install seletoolsfrom seletools.actions import drag_and_dropsource driver.find_element(By.CSS_SELECTOR, #column-a)target browser.find_element(By.CSS_SELECTOR, #column-b)drag_and_drop(driver, source, target)如果使用的是JavaSelenium技术栈则可以使用以下代码实现 // 要拖拽的元素WebElement draggable driver.findElement(By.xpath());// 目标元素WebElement droppable driver.findElement(By.xpath());// 拖动前先点击并按住要拖拽的元素避免在elementui拖放前draggable属性才会变成true目的是让draggable变成true如果一开始就是true也可不加这句new Actions(driver).clickAndHold(draggable).perform();final String java_script var args arguments, callback args[args.length - 1], source args[0], target args[1], offsetX (args.length 2 args[2]) || 0, offsetY (args.length 3 args[3]) || 0, delay (args.length 4 args[4]) || 1; if (!source.draggable) throw new Error(Source element is not draggable.); var doc source.ownerDocument, win doc.defaultView, rect1 source.getBoundingClientRect(), rect2 target ? target.getBoundingClientRect() : rect1, x rect1.left (rect1.width 1), y rect1.top (rect1.height 1), x2 rect2.left (rect2.width 1) offsetX, y2 rect2.top (rect2.height 1) offsetY, dataTransfer Object.create(Object.prototype, { _items: { value: { } }, effectAllowed: { value: all, writable: true }, dropEffect: { value: move, writable: true }, files: { get: function () { return undefined } }, types: { get: function () { return Object.keys(this._items) } }, setData: { value: function (format, data) { this._items[format] data } }, getData: { value: function (format) { return this._items[format] } }, clearData: { value: function (format) { delete this._items[format] } }, setDragImage: { value: function () { } } }); target doc.elementFromPoint(x2, y2); if(!target) throw new Error(The target element is not interactable and need to be scrolled into the view.); rect2 target.getBoundingClientRect(); emit(source, dragstart, delay, function () { var rect3 target.getBoundingClientRect(); x rect3.left x2 - rect2.left; y rect3.top y2 - rect2.top; emit(target, dragenter, 1, function () { emit(target, dragover, delay, function () { \ttarget doc.elementFromPoint(x, y); \temit(target, drop, 1, function () { \t emit(source, dragend, 1, callback); });});});}); function emit(element, type, delay, callback) { var event doc.createEvent(DragEvent); event.initMouseEvent(type, true, true, win, 0, 0, 0, x, y, false, false, false, false, 0, null); Object.defineProperty(event, dataTransfer, { get: function () { return dataTransfer } }); element.dispatchEvent(event); win.setTimeout(callback, delay); };// 默认拖拽到中心点位置第3个参数是X坐标偏移量左负右正第4个参数为Y坐标偏移量上负下正第5个参数是延迟时间单位为毫秒表示当鼠标点下后延迟指定时间后才开始激活拖拽动作用来防止误点击((JavascriptExecutor) driver).executeScript(java_script, draggable, droppable, -200, -300, 500);以上就是在Python和Java中的解决方案至于为什么不在Selenium中直接修改程序而是创建单独的包来处理以下是Dmitrii Bormotov的说法 The drag and drop bug is a webdriver issue, so all you can do on the Selenium side is to simply perform the same workaround that I did. I spoke with David Burnes (core Selenium committer) about pushing that workaround into Selenium, but he said that it is not a good idea to have any workarounds in Selenium itself. That is why I had to create a separate package to help the test automation community with this problem.大概的意思就是拖放错误是一个webdriver网络驱动问题David Burnes核心 Selenium 提交者认为在Selenium中提供任何暂时避开网络的方法并不是一个好主意。 总结 感谢每一个认真阅读我文章的人 作为一位过来人也是希望大家少走一些弯路如果你不想再体验一次学习时找不到资料没人解答问题坚持几天便放弃的感受的话在这里我给大家分享一些自动化测试的学习资源希望能给你前进的路上带来帮助。 软件测试面试文档 我们学习必然是为了找到高薪的工作下面这些面试题是来自阿里、腾讯、字节等一线互联网大厂最新的面试资料并且有字节大佬给出了权威的解答刷完这一套面试资料相信大家都能找到满意的工作。 视频文档获取方式 这份文档和视频资料对于想从事【软件测试】的朋友来说应该是最全面最完整的备战仓库这个仓库也陪伴我走过了最艰难的路程希望也能帮助到你以上均可以分享点下方小卡片即可自行领取。
- 上一篇: 网站后台邮箱配置app软件系统开发
- 下一篇: 网站后台怎么上传图片各大城市网站哪里做
相关文章
-
网站后台邮箱配置app软件系统开发
网站后台邮箱配置app软件系统开发
- 技术栈
- 2026年03月21日
-
网站后台用什么做招聘类网站怎么做
网站后台用什么做招聘类网站怎么做
- 技术栈
- 2026年03月21日
-
网站后台用户名密码嘉兴港区建设局网站
网站后台用户名密码嘉兴港区建设局网站
- 技术栈
- 2026年03月21日
-
网站后台怎么上传图片各大城市网站哪里做
网站后台怎么上传图片各大城市网站哪里做
- 技术栈
- 2026年03月21日
-
网站后台怎么做下载链接网站备案名称的影响吗
网站后台怎么做下载链接网站备案名称的影响吗
- 技术栈
- 2026年03月21日
-
网站后台做完文章不显示现在网站如何做优化
网站后台做完文章不显示现在网站如何做优化
- 技术栈
- 2026年03月21日
