フレームの上にドラッグされたすべての要素が反復されるように、ドロップされます。クラス名を繰り返して、同じクラス名の関連オブジェクトをすべてjavaのセレニウムでクリックするようにします
これを達成するには、以下のコードを書いたところで、getClassがすべての要素を取得する必要があるようです。 getClassが削除されると、2つの要素だけが検出され、さらに多くの要素が削除されるということです。
「getClass」を持っている必要があり、すべての要素がクリックされるようにa.ui-icon.ui-icon-refreshのクラス全体を取得する別の方法がありますか?すべての
package Testing;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import java.util.Iterator;
import java.util.List;
public class Radiobuttons {
public static void main(String[] args)
{
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver","C://chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://jqueryui.com/droppable/");
System.out.println(driver.getTitle());
WebElement SimplePhotoManager = driver.findElement(By.xpath("//*[@id=\"content\"]/div[1]/ul/li[5]/a"));
SimplePhotoManager.click();
driver.switchTo().frame(driver.findElement(By.xpath("//*[@id=\"content\"]/iframe")));
WebElement source1 = driver.findElement(By.xpath("//*[@id=\"gallery\"]/li[1]"));
WebElement source2 = driver.findElement(By.xpath("//*[@id=\"gallery\"]/li[2]"));
WebElement source3 = driver.findElement(By.xpath("//*[@id=\"gallery\"]/li[3]"));
WebElement source4 = driver.findElement(By.xpath("//*[@id=\"gallery\"]/li[4]"));
WebElement targetBefore = driver.findElement(By.xpath("//*[@id=\"trash\"]"));
Actions a = new Actions(driver);
a.dragAndDrop(source1, targetBefore).build().perform();
a.dragAndDrop(source2, targetBefore).build().perform();
a.dragAndDrop(source3, targetBefore).build().perform();
a.dragAndDrop(source4, targetBefore).build().perform();
//Why is this required?
List<WebElement> getClass= driver.findElements(By.className("a.ui-icon"));
//Grab common attribute//Put into list and iterate
int count=driver.findElements(By.className("ui-icon-refresh")).size();
System.out.println(count);
for(int i=0;i<count;i++)
{
driver.findElements(By.className("ui-icon-refresh")).get(i).click();
}
//Close the thing
//driver.quit();
}
}