我有一個問題,我想將滑鼠懸停在某個按鈕上(進行開發),但我不想點擊它,我不知道該怎么做。當我單擊此按鈕時,它會將我帶到另一個地方而我不想要它
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();
}
uj5u.com熱心網友回復:
要將滑鼠懸停在某個按鈕上但要避免單擊它,您必須為所需的WebDriverWait引入WebDriverWaitElementIsVisible()并使用Actions 類方法,如下所示:
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();
參考
您可以在以下位置找到一些相關的詳細討論:
- 使用動態滑鼠懸停事件抓取網站
- 如何通過 selenium-webdriver 和 Java 使用 java 滑鼠懸停
uj5u.com熱心網友回復:
您可以Action在找到要懸停的元素后使用
var element = driver.FindElement(By.XPath("//div[@class='css-1povu0j']"));
Actions action = new Actions(driver);
action.MoveToElement(element).Perform();
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/366544.html
上一篇:無法在其他頁面中獲取“href”
