Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to click on a specific position of a web element in selenium?

I am working on video player automation. I am having difficulties in clicking at the end of the video player progress bar.
Consider an example of youtube video. with the help of xpath i was able to find out the element of video progress bar. Now i wanted to click at the end of the video.

i tried using moveToElement(ele, xOffset, yOffset). But i can not have static offset here as the video player size depends on the browser window size. I tried to get the size of web element and use it as xoffset but that did not seem to be working. moveToElement(ele, ele.getRect().getWidth()-10, yOffset). Any suggestions here on how to achieve this?

like image 562
user2649233 Avatar asked Nov 11 '16 10:11

user2649233


1 Answers

Try this code. I tried on Chrome 54 with webdriver 2.53 on windows 8. Do not touch the mouse during test or even better move the cursor out of screen range when test starts.

   WebElement elem = driver.findElement(By.className("ytp-progress-bar"));

    int width = elem.getSize().getWidth();

    Actions act = new Actions(driver);
    act.moveToElement(elem).moveByOffset((width/2)-2, 0).click().perform();

You can figure out the offset from the many attributes in the div 'ytp-progress-bar'. You do not need to find width etc.

You have to move to the progress bar initially because it disappears after 2-3 secs due to inactivity on the video screen.

like image 83
Grasshopper Avatar answered Oct 12 '22 23:10

Grasshopper