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("[email protected]"); 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();


        }
3

2 Answers 2

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:

Sign up to request clarification or add additional context in comments.

Comments

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();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.