Home > Blockchain >  Selenium Test cant send Key "DELETE" on div
Selenium Test cant send Key "DELETE" on div

Time:12-09

I am trying to test my application with selenium. I have a grid with divs, where you can enter or delete projects. To delete a project you have to press the "DELETE" button after selecting the div.

Selenium Test

[Fact]
public void DeleteBooking_ExistingProject_Success()
{
    // Arrange
    _driver.Navigate().GoToUrl(Consts.FIXPLANUNG_URL);
    _driver.MicrosoftLogin(_configService.Get("Email"), _configService.Get("Password"));

    // Act
    var bookingFieldXPath = FindBookingFieldXPath(Consts.DUMMY_PROJECT);
    if (string.IsNullOrWhiteSpace(bookingFieldXPath))
    {
        Assert.Fail("No booking field was found");
    }

    var bookingField = _driver.FindElement(By.XPath(bookingFieldXPath));

    bookingField.Click();
    Thread.Sleep(1000);
    bookingField.SendKeys(Keys.Delete);
    Thread.Sleep(1000);

    _driver.Navigate().Refresh();
    Thread.Sleep(7000);

    var result = _driver.FindElement(By.XPath(bookingFieldXPath)).Text;

    // Assert
    Assert.NotNull(result);
    Assert.True(string.IsNullOrWhiteSpace(result));
}

OpenQA.Selenium.ElementNotInteractableException: 'Element is not reachable by keyboard'

CodePudding user response:

try to use act:

[Fact]
public void DeleteBooking_ExistingProject_Success()
{
    // Arrange
    **var act = new Actions(_driver);**
    _driver.Navigate().GoToUrl(Consts.FIXPLANUNG_URL);
    _driver.MicrosoftLogin(_configService.Get("Email"), _configService.Get("Password"));

    // Act
    var bookingFieldXPath = FindBookingFieldXPath(Consts.DUMMY_PROJECT);
    if (string.IsNullOrWhiteSpace(bookingFieldXPath))
    {
        Assert.Fail("No booking field was found");
    }

    var bookingField = _driver.FindElement(By.XPath(bookingFieldXPath));

    **act.Click(bookingField).Perform();**
    Thread.Sleep(1000);
    **act.SendKeys(Keys.Delete);**
    Thread.Sleep(1000);

    _driver.Navigate().Refresh();
    Thread.Sleep(7000);

    var result = _driver.FindElement(By.XPath(bookingFieldXPath)).Text;

    // Assert
    Assert.NotNull(result);
    Assert.True(string.IsNullOrWhiteSpace(result));
}
  • Related