我正在練習硒鼠標懸停和使用網站 - http://www.flipkart.com,我從「電子」菜單中選擇「三星」。下面是我的代碼,但即使xpaths正確,它也不起作用。Selenium:無法找到元素
@CacheLookup
@FindBy(xpath="//a[@data-tracking-id='electronics']") WebElement Electronics_Menu;
@CacheLookup
@FindBy(xpath=".//*[@id='menu-electronics-tab-0-content']//a[text()='Samsung']") WebElement Samsung_Mobile_Click;
Actions act = new Actions(driver);
act.moveToElement(Electronics_Menu).perform();
act.click(Samsung_Mobile_Click).build().perform();
這是我的錯誤,當我運行代碼:
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":".//*[@id='menu-electronics-tab-0-content']//a[text()='Samsung']"}
Command duration or timeout: 27.04 seconds
試試這個'XPath':'// a [@ title =「Samsung」]' – Andersson
Thanks !!它的工作:) – Bimlesh