JavaでSelenium 3、Cucumber & ChromeDriverを使用しています。私はimg要素からドラッグしようとしていますが、Seleniumはドラッグアンドドロップするためにその要素にフォーカスを移動することはできません。私は以下のすべてのオプションを試しました。 Pls。もし誰かが助けることができたら教えてください。Selenium webdriver 3を使用してドラッグする方法。ドラッグ元要素が<img>タグ
使用してキーボードアクション:
Actions builder = new Actions(driver);
builder.keyDown(Keys.CONTROL).click(someElement).click(someOtherElement). keyUp(Keys.CONTROL).build().perform();
用いて、マウスアクション:
Actions builder = new Actions(driver);
builder.clickAndHold(someElement).moveToElement(otherElement).release(otherElement).build().perform();
コードは、Robotクラスで罰金作品:= objHelp.WaitForElement(ドライバ
public String dragElementFrom="//div[@class='asset-instructions col-xs-6']/div[5]/div/ul/li[1]/div/img";
public String dragElementTo="//*[@id='parity-on-page-preview']";
WebElement電子によって.xpath(obj.dragElementFrom)); WebElement f = objHelp.WaitForElement(ドライバ、By.xpath(obj.dragElementTo));
Point coordinates1 = e.getLocation();
Point coordinates2 = f.getLocation();
Robot robot = new Robot();
robot.mouseMove(coordinates1.getX()+55, coordinates1.getY()+118);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseMove(coordinates2.getX()+200, coordinates2.getY()+200);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
Thread.sleep(2000);
私はテストを実行するとき、私はブラウザウィンドウがロボットクラスが動作しないことに焦点を当てていることを確認する必要があります。
私もFirefoxを使ってみましたが、同じです。また、私はstackoverflowを研究したがどこでも私の答えを見つけることができませんでした。