Rain
Rain

Reputation: 239

Is it possible to find an element like a button and click it, when it is continuously moving on? e.g Carousel

I am using Selenium Webdriver(Ruby) to automate my web app and my web app has this carousel wherein my element continuously keeps moving in a loop. By the time I locate that element and try to click it, element moves ahead.Hence I am not able to locate that element. I tried finding and clicking that moving element by following code:

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

I thought that by 'sleep 10' I could make that element wait for 10 seconds and then click it.But this does not work and I am getting ElementNotVisibleError whenever I run my script.

Question:

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

Upvotes: 4

Views: 229

Answers (3)

Shubham Jain
Shubham Jain

Reputation: 17553

Another thing you can do, as we doing in selenium with java that put the implicitlyWait according to the time on which your button came back after one rotation; now perform click just after 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

In ruby you have to use this type of syntax

@driver.manage.timeouts.implicit_wait = 30

Upvotes: 0

Storm
Storm

Reputation: 758

Why are the actions divided?

I would recommend the following:

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

so it will find the object and click on it.

Upvotes: 0

Husam
Husam

Reputation: 1105

Yes it is absolutely possible. I handled same scenario for carousel on my site. There are three ways:

  • Most carousel stop on mouse hover. So you may use it to stop the carousel. Use Actions class to move over to the carousel. Once it stops you may click on it.
  • If you want a specific slide, you can click on dots or any other navigator, like prev/nxt, to reach your slide and then click it.
  • The sure shot way to click your specific slide, without worrying about whether it is displayed or not is to use Javascript to click it (Which I had done in my case although I had also implemented 2nd way but I found javascript the simplest solution).

Upvotes: 0

Related Questions