0

I have a problem, I want to hover over a certain button (to develop) but I don't want to click it, I don't know how to do it. when I click this button, it takes me to another place and I don't want it

 private void button1_Click(object sender, EventArgs e)
        {
            string url = textBox1.Text;
            driver.Navigate().GoToUrl(url); Thread.Sleep(2000);

            driver.FindElement(By.XPath("//button[@id='onetrust-accept-btn-handler']")).Click(); Thread.Sleep(3000);

            driver.FindElement(By.XPath("//a[normalize-space()='Mój OLX']")).Click(); Thread.Sleep(2000); 

            driver.FindElement(By.XPath("//section[@class='login-page has-animation']//input[@id='userEmail']")).SendKeys("anastazja.bendkowska@wp.pl"); Thread.Sleep(3000);

            driver.FindElement(By.XPath("//input[@id='userPass']")).SendKeys("Anastazja12345");

            driver.FindElement(By.XPath("//section[@class='login-page has-animation']//button[@id='se_userLogin']")).Click(); Thread.Sleep(3000);

            driver.FindElement(By.XPath("//div[@class='css-1povu0j']"));


            //driver.FindElement(By.XPath("//a[normalize-space()='Wyloguj']")).Click();
            //driver.FindElement(By.XPath("")).Click();


        }
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
thomas2075
  • 31
  • 6
  • Does this answer your question? [How to do a mouse over using selenium webdriver to see the hidden menu without performing any mouse clicks?](https://stackoverflow.com/questions/20355515/how-to-do-a-mouse-over-using-selenium-webdriver-to-see-the-hidden-menu-without-p) – gunr2171 Nov 24 '21 at 13:36
  • not so much, I want to hover over an element without clicking on it and this post is about something else – thomas2075 Nov 24 '21 at 13:51
  • The mentioned "action.MoveToElement" method in @gunr2171 link seems spot on to me. – Ralf Nov 24 '21 at 14:58

2 Answers2

1

To hover over a certain button but to avoid clicking it you have to induce WebDriverWait for the desired ElementIsVisible() and the use Actions Class methods as follows:

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
var element = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//a[normalize-space()='Wyloguj']")));

Actions action  = new Actions(driver);
action.MoveToElement(element).Perform();

References

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

You can use the Action after you find the element you want to hover

    var element = driver.FindElement(By.XPath("//div[@class='css-1povu0j']"));
    Actions action  = new Actions(driver);
    action.MoveToElement(element).Perform();
Karnafun
  • 96
  • 6