link我正在尝试使用下面的代码从源代码拖放到目标但是它没有通过不同的定位器找到我的源元素。
我有一个button
,当点击它导致新的popup
窗口,我可以切换到新窗口,但它没有找到我的元素执行拖放。
我的代码:
//While clicking on this button , It opens a new window
Managedealassets.click();
//Switching my control to the new window
driver.switchTo().defaultContent();
WebElement From = driver.findElement(By.xpath("html/body/div[21]/div[2]/div/div[2]/div/ul/li/ul/li/div/span"));
WebElement To = driver.findElement(By.xpath("html/body/div[21]/div[2]/div/div[1]/div/ul/li/div/span"));
Actions builder = new Actions(driver);
Action dragAndDrop = builder.clickAndHold(From)
.moveToElement(To)
.release(To)
.build();
dragAndDrop.perform();
}
}
HTML代码:
我已为HTML
代码附加了一个屏幕
Managedealassets.click(); `/Switching my control to the new window
driver.switchTo().defaultContent();
WebElement From = driver.findElement(By.id("SelectedAssets"));
List<WebElement> DealAssignedAssets = From.findElements(By.tagName("span"));
for (WebElement element : DealAssignedAssets) {
if (element.getText().equals("Various vehicles"));
{
WebElement To = driver.findElement(By.id("UnAssignedApplicationAssets"));
List<WebElement> UnAssignedApplicationAssets = To.findElements(By.tagName("span"));
for (WebElement element11 : UnAssignedApplicationAssets ) {
if (element.getText().equals("Various LDV's"));
Actions builder = new Actions(driver);
Action dragAndDrop = builder.clickAndHold(element)
.moveToElement(element11).release().build();
dragAndDrop.perform();
}`