Is it possible to find an element as a button and click on it when it is constantly moving on? e.g. carousel

I use Selenium Webdriver (Ruby) to automate my web application, and my web application has this carousel, in which my element constantly moves in a loop. By the time I find this item and try to click it, the item is moving forward. I can’t find this item. I tried to find and click this moving element by running the following code:

    {
    ele_button = driver.find_element(:xpath,"xpath")
    sleep 10
    ele_button.click
    }

I thought that β€œsleep 10” could make this element wait 10 seconds and then click it. But this does not work, and I get an ElementNotVisibleError whenever I run my script.

Question:

Is it possible to automate a moving element? If yes, please provide me a solution.

+4
source share
3 answers

Yes, it is absolutely possible. I processed the same script for a carousel on my site. There are three ways:

  • The large carousel stops when you hover over the mouse. Therefore, you can use it to stop the carousel. Use the Actions class to go to the carousel. After that you can click on it.
  • If you want to use a specific slide, you can click dots or any other navigator, such as prev / nxt, to go to the slide and then click on it.
  • , , , Javascript ( , , javascript ).
0

?

:

driver.find_element(:xpath,"xpath").click()

.

0

, , java, implicitlyWait , ; implicitlyWait

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
// Suppose a rotation of button takes 30 sec

driver.findElement(By.xpath("/html/body/div[2]")).click();
// action performs on the element

ruby ​​

@driver.manage.timeouts.implicit_wait = 30
0

Source: https://habr.com/ru/post/1526352/


All Articles