Перейти к содержимому

Фотография

Right Click() выбранного объекта


  • Авторизуйтесь для ответа в теме
Сообщений в теме: 3

#1 Vikonder

Vikonder

    Новый участник

  • Members
  • Pip
  • 31 сообщений

Отправлено 05 мая 2018 - 09:42

Камрады!

 

Не получается реализовать работающий метод нажатие правой кнопки мышки.после наведения на элемент

 

Метод нажатия:

 

 

@Step(description = "Right click")
public static void RightClick(WebDriver driver, By targetXpath)
{
WebElement element = driver.findElement(targetXpath);
Actions action = new Actions(driver);
action.contextClick(element).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ENTER).perform();

}

 

Метод наведения

 

 

@Step(description = "Mouse Hover to target")
public static void mouseHover(WebDriver driver, WebElement element) {
Actions action = new Actions(driver);
action.moveToElement(element).perform();

}

 

В главном теле программы:

 

        String xpath = String.format(<xpath to element>);

        By deviceXpath = By.xpath(xpath);
        WebElement deviceElement = driver.findElement(deviceXpath);
        waitForElementToBeVisible(deviceXpath);
 
        CommonWebSteps.mouseHover(driver, deviceElement);
        CommonWebSteps.RightClick(driver, deviceXpath);

 

В результате, мышка наводится на элемент, но никакого Right Click() не происходит...

 

Должно быть выпадающее под-меню вот так 

Прикрепленный файл  ScreenHunter_193 May. 05 12.42.jpg   7,2К   0 Количество загрузок:

 

Исполнение не падает, просто ничего не происходит...

 

 


  • 0

#2 Vikonder

Vikonder

    Новый участник

  • Members
  • Pip
  • 31 сообщений

Отправлено 05 мая 2018 - 11:42

В добавок, простое нажатие правой кнопки тоже не работает

 

 

 

@Step(description = "Right click")
public static void RightClick(WebDriver driver, By targetXpath)
{
WebElement element = driver.findElement(targetXpath);
Actions action = new Actions(driver);
action.contextClick(element).perform();    // ---------------- simple RightClick

}


  • 0

#3 lapa

lapa

    Новый участник

  • Members
  • Pip
  • 55 сообщений


Отправлено 07 мая 2018 - 06:56

action.moveToElement(driver.findElement(by)).contextClick().build().perform();

 

попробуйте так


  • 0

#4 Vikonder

Vikonder

    Новый участник

  • Members
  • Pip
  • 31 сообщений

Отправлено 07 мая 2018 - 19:05

так пробовал тоже...

не работает...

 

Есть подозрения в поддержке данного метода разными версиями geckodriver

и соответсвующей версией FireFox

 

На работе стояла 0.19 и 55 (так требует клиент) - и такая парочка не заработала...

 

Дома, вот этот код прекрасно работает:  (пользуйтесь кому надо)

 

 

package right_click;

 
            import org.openqa.selenium.Alert;
            import org.openqa.selenium.By;
            import org.openqa.selenium.NoSuchElementException;
            import org.openqa.selenium.StaleElementReferenceException;
            import org.openqa.selenium.WebDriver;
            import org.openqa.selenium.WebElement;
            import org.openqa.selenium.firefox.FirefoxDriver;
            import org.openqa.selenium.interactions.Actions;
            import org.openqa.selenium.support.ui.ExpectedConditions;
            import org.openqa.selenium.support.ui.WebDriverWait;
            import org.testng.Assert;
            import org.testng.annotations.AfterClass;
            import org.testng.annotations.BeforeClass;
            import org.testng.annotations.Test;
 
public class right_click {
 
    WebDriver driver;
 
 
    @BeforeClass
    public void Setup() {
        System.setProperty("webdriver.firefox.marionette","C://selenium/geckodriver.exe");
        driver = new FirefoxDriver();
        driver.manage().window().maximize();
    }
 
    @Test
    public void rightClickTest() {
        driver.navigate().to(URL);
        By locator = By.xpath("//span[@class='context-menu-one btn btn-neutral']");
        WebDriverWait wait = new WebDriverWait(driver, 5);
        wait.until(ExpectedConditions.presenceOfElementLocated(locator));
        WebElement element=driver.findElement(locator);
        rightClick(element);
        WebElement elementEdit =driver.findElement(By.xpath("//li[@class='context-menu-item context-menu-icon context-menu-icon-edit']"));
        elementEdit.click();
        Alert alert=driver.switchTo().alert();
        String textEdit = alert.getText();
        Assert.assertEquals(textEdit, "clicked: edit", "Failed to click on Edit link");
    }
 
    public void rightClick(WebElement element) {
            Actions action = new Actions(driver).contextClick(element);
            action.build().perform();
 
    }
 
    @AfterClass
    public void tearDown() {
        driver.quit();
    }
 
 
}
 
на работе - нет... 
Хрень какая-то

  • 0


Количество пользователей, читающих эту тему: 0

0 пользователей, 0 гостей, 0 анонимных