Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium 使用webdriver操作裁剪图像_Selenium_Selenium Webdriver_Crop - Fatal编程技术网

Selenium 使用webdriver操作裁剪图像

Selenium 使用webdriver操作裁剪图像,selenium,selenium-webdriver,crop,Selenium,Selenium Webdriver,Crop,我有一个模态框出现,其中包含我希望使用Selenium裁剪的图像 <div class="crop" style="width: 380px; height: 204px; position: absolute; top: -2px; left: -2px; z-index: 280; cursor: crosshair;"></div> 其中cropTracker是Web元素即crop的正确xpath 我在执行时看到的是,模式只是瞬间闪烁,而不是如所附图像所示执行裁

我有一个模态框出现,其中包含我希望使用Selenium裁剪的图像

<div class="crop" style="width: 380px; height: 204px; position: absolute; top: -2px; left: -2px; z-index: 280; cursor: crosshair;"></div>

其中cropTracker是Web元素即crop的正确xpath

我在执行时看到的是,模式只是瞬间闪烁,而不是如所附图像所示执行裁剪拖动;不知道我做错了什么

试试这个

Action crop = new Actions(driver);
crop.clickAndHold(cropTracker).moveByOffset(30, 50).release().build().perform();
/*it will first click and Hold the cropTracker Element, after that it will move to the 
30px right side and 50px upward.*/

在我们的客户化框架中,我们使用如下内容:

Actions actions = new Actions(driver);
        action.ClickAndHold(elementToDrag);
        action.MoveToElement(elementToDropOn, 5, 5);
        action.Perform();
        Thread.Sleep(250); //note the sleep here. magic sleep.
        action.Release(elementToDropOn);
        action.Perform();

我尝试了这个,但是由于某种原因发布事件/操作没有被触发;如果我在下一个线程中按@Stas所示将其分解,那么在release().perform()之后,裁剪元素将闪烁,并且不会释放裁剪元素。
Actions actions = new Actions(driver);
        action.ClickAndHold(elementToDrag);
        action.MoveToElement(elementToDropOn, 5, 5);
        action.Perform();
        Thread.Sleep(250); //note the sleep here. magic sleep.
        action.Release(elementToDropOn);
        action.Perform();