2

I am browsing the url:

http://serve.qa.vdopia.com/adserver/html5/inwapads/?sleepAfter=0;adFormat=banner;ak=e833a81e238ce8dc876a5f0a283953c2;version=1.0;cb=[timestamp];output=html. 

I am trying to click the image located by xpath=//a/img[1], but I can't click it though I am able to find it successfully. I have tried these options so far, but none of them are successful yet. Any help will be appreciated.

//#1.
    WebElement bannerImage = driver.findElement(By.xpath("//a/img[1]"));
    bannerImage.click();

//#2.       
    WebElement bannerImage = driver.findElement(By.xpath("//a/img[1]"));
    TouchActions flick = new TouchActions(driver).flick(bannerImage, -100, 0, 0);
    flick.perform();

//#3.
    String xpath = "//a/img[1]";
    String js = "var targetElement = document.evaluate(\""+xpath+"\",document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue;"
        +"var evt = document.createEvent('UIEvent');"
        +"evt.initUIEvent('touchstart', true, true);"
        +"targetElement.dispatchEvent(evt);";
    ((JavascriptExecutor)driver).executeScript(js);
Will
  • 24,082
  • 14
  • 97
  • 108
Pankaj Kumar Katiyar
  • 1,474
  • 1
  • 20
  • 36
  • Can you partially see the element? I have run into the a problem, not being to able to click some elements that are partially visible. – Madis Kangro Jul 10 '15 at 07:44
  • element is clearly visible, I can find it easily and get the property also. – Pankaj Kumar Katiyar Jul 10 '15 at 07:48
  • Hmm. maybe this can help you out. It does work for me when normal click doesnt work. Point elementpointer = driver.findElement(By.xpath("//a/img[1]")).getLocation(); TouchActions actions=new TouchActions(driver); actions.down(elementpointer.x, elementpointer.y); actions.up(elementpointer.x, elementpointer.y); actions.perform(); } – Madis Kangro Jul 10 '15 at 07:54
  • @Madis Kangro: well I tried the your solution but it doesn't work. Surprisingly I can't click the image in AndroidDriver Webview App manually but the image is naturally clickable in Chrome (Browser) in Android Mobile. I've checked few other sites in AndroidDriver Webview App it looks like the app it self is blocking any click which has redirection to any other url, luckily the above image which I've been trying to click, has a redirection url. Is it possible the AndroidDriver Webview App itself has some issues. – Pankaj Kumar Katiyar Jul 10 '15 at 09:08
  • What selendroid version are you using also. Could be an issue of the androiddriver WebView App. – Madis Kangro Jul 10 '15 at 09:34
  • @Madis Kangro: I am using standalone-selendroid-0.9.0-with-dependencies.jar – Pankaj Kumar Katiyar Jul 10 '15 at 10:26
  • Could you try with a newer version. They could have fixed the issue. 0.15 is currently the newest. – Madis Kangro Jul 10 '15 at 10:31
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/82936/discussion-between-pankaj-and-madis-kangro). – Pankaj Kumar Katiyar Jul 10 '15 at 11:44
  • @Madis Kangro: I tried with selendroid v0.15 too, still I couldn't click on image. – Pankaj Kumar Katiyar Jul 13 '15 at 07:33

0 Answers0