[英]How to click on an element which is visible after mouse hover over an element within ebay.com using Selenium and Java
I am trying to learn selenium with java using ebay.com . 我正在尝试使用ebay.com与java学习硒。 I found a difficult element to select element after mouse hover. 鼠标悬停后,我发现很难选择元素。 Here is my snippet code 这是我的代码片段
driver.findElement(By.xpath("//a[contains(text(),'Tennis')]")).click()
However above code return error element not interactable 但是上述代码返回错误元素不可交互
I have add Thread.sleep(60000)
before driver.findElement
and still not able to click 我在driver.findElement
之前添加了Thread.sleep(60000)
, driver.findElement
仍然无法单击
here is the window i wanted to click 这是我要单击的窗口
Hover to Sports menu using Actions
and when menu opens click to the Tennis submenu. 悬停体育菜单使用Actions
和菜单打开时,点击到网球子菜单。 To wait for Tennis to be clickable use WebDriverWait
: 要等待网球可点击,请使用WebDriverWait
:
WebDriverWait wait = new WebDriverWait(driver, 5);
Actions actions = new Actions(driver);
driver.get("https://www.ebay.com");
WebElement sports = driver.findElement(By.linkText("Sports"));
actions.moveToElement(sports).perform();
wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Tennis"))).click();
You need to Mouse Hover over the element with text as Sports and wait for the elementToBeClickable()
with text as Tennis and you can use the following solution: 您需要将鼠标悬停在文本为“ 体育”的元素上,并等待文本为Tennis的elementToBeClickable()
,然后可以使用以下解决方案:
Code Block: 代码块:
System.setProperty("webdriver.chrome.driver", "C:\\\\Utility\\\\BrowserDrivers\\\\chromedriver.exe"); ChromeOptions options = new ChromeOptions(); options.addArguments("start-maximized"); options.addArguments("--disable-extensions"); //options.addArguments("disable-infobars"); WebDriver driver = new ChromeDriver(options); driver.get("https://www.ebay.com/"); new Actions(driver).moveToElement(new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Sports")))).perform(); new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[text()='Sports']//following::div[@class='hl-cat-nav__flyout']//span[text()='Other Categories']//following::ul[1]/li/a[normalize-space()='Tennis']"))).click();
Browser Snapshot: 浏览器快照:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.