Используется страница теста автоматизации: https://demoqa.com/образное время sudo:
[*] chrome
ure url
< /ol>
Целый скрипт: < /p>
Код: Выделить всё
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium.Support.UI;
using System.Xml.Linq;
using SeleniumExtras.WaitHelpers;
namespace SeleniumProject03;
public class DemoQASimpleLoginTest
{
private IWebDriver driver;
[SetUp]
public void Setup()
{
driver = new ChromeDriver();
driver.Navigate().GoToUrl("https://demoqa.com/");
driver.Manage().Window.Maximize();
}
[Test]
public void Login ()
{
IWebElement bookCard = driver.FindElement(By.XPath("//h5[text()='Book Store Application']/ancestor::div[contains(@class, 'top-card')]"));
// Not working
try
{
Actions actions = new Actions(driver);
actions.MoveToElement(bookCard).Click().Perform();
}
catch (Exception ex)
{
Console.WriteLine("Error scrolling to the element: " + ex.Message);
}
try
{
bookCard.Click();
}
catch (Exception ex1)
{
Console.WriteLine("Error clicking the element: " + ex1.Message);
}
// Working
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView(true);", bookCard);
bookCard.Click();
}
[TearDown]
public void TearDown()
{
Thread.Sleep(5000);
// Close the browser
if (driver != null)
{
driver.Dispose();
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... -clik-does