Dalam skenario di bawah ini, saya mencoba memilih Option4-1 dari menu utama. Telah menggunakan moveToElement(), click(). use case menunjukkan sebagai pass ketika saya menjalankan skrip saya tetapi saya tidak melihat slide di jendela muncul yang merupakan perilaku yang diharapkan setelah mengklik "option4-1".

Image shows option menus

Kode:

public class CreateppPage extends PageFactory {

private WebDriver driver;
private WebDriverWait wait;
private Actions act;
/**
      Selectors section
 */

@FindBy(xpath = "//div[@class='Main Button']")
private WebElement AddMenu;
@FindBy(xpath="//li[@class='item-submenu']//span[contains(text(),'Option4')]")
private WebElement subMenu;
@FindBy(xpath="//span[contains(text(),'Option4-1')]")
private WebElement subsubMenu;

/*****************Methods section***********************/

public CreateppPage(WebDriver driver, long wait) {
    
    this.driver = driver;
    this.wait = new WebDriverWait(driver,wait);
    initElements(driver, this);
    driver.manage().timeouts().implicitlyWait(5000, TimeUnit.MILLISECONDS);
}

public void createMpp() {
    
    wait.until(ExpectedConditions.visibilityOf(AddMenu));
    act = new Actions(driver);
    try {
        Thread.sleep(2000);
        act.moveToElement(AddMenu).click().build();
        Thread.sleep(1000);
        act.moveToElement(subMenu).click().moveToElement(subsubMenu).click().build();
        Thread.sleep(10000);    
    }
    catch(Exception e) {
        System.out.println(e.getCause());
    }
}
}
1
vinsr04 17 Juni 2021, 12:35

2 jawaban

moveToElement() Moves the mouse to the middle of the element.

Build(): creates the chain of the actions that need to be 
performed

perform(): perform those chain of actions which is build by using 
Action build method.

Internally the perform() called the build() method so if we call 
the perform().build() explicitly so we are calling .build() twice

So it seems like you miss the .perform()

act.moveToElement(subMenu).click()
.moveToElement(subsubMenu).click().build().perform();

OR

act.moveToElement(subMenu).click()
.moveToElement(subsubMenu).click().perform();

.perform() : Metode praktis untuk melakukan tindakan tanpa memanggil build() terlebih dahulu.

0
YaDav MaNish 17 Juni 2021, 19:37

Saya mungkin akan melakukan seperti ini:

new Actions(driver).moveToElement(AddMenu).click().moveToElement(subsubMenu).click().build().perform();
1
cruisepandey 17 Juni 2021, 10:37