Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Selenium Test cant send Key "DELETE" on div

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’

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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));
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading