2

In facebook navigate to Home and try to click on Add Photos/Videos to bring up the file upload window but it always gives an exception "Element is not clickable at point ..."

I tried the methods given in the first answer of Debugging "Element is not clickable at point" error but nothing works.

Edit:

Code:

1.

WebElement element= driver.findElement(By.xpath("//span[text()='Add Photos/Video']"));
element.click();

2

WebElement element= driver.findElement(By.xpath("//span[text()='Add Photos/Video']"));
element.sendKeys(Keys.RETURN);

3

Actions actions = new Actions(driver);
actions.moveToElement(element).click().perform();

4.

JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].click();", element);
Community
  • 1
  • 1
ilm
  • 145
  • 7

3 Answers3

0

Try this:

IJavaScriptExecutor ex = (IJavaScriptExecutor)Driver;
ex.ExecuteScript("arguments[0].click();", elementToClick);
Zizouz212
  • 4,908
  • 5
  • 42
  • 66
  • Shouldn't it be JavascriptExecutor and not IJavaScriptExecutor ? If so then I have tried it and it doesn't work – ilm Feb 18 '16 at 13:12
  • In general you shouldn't use JSE because it's not how the user would interact with the page. – JeffC Feb 18 '16 at 16:10
  • @JeffC But I've seen JsE work when all other alternatives have failed. So it can be useful. – ilm Feb 19 '16 at 03:12
  • Yes, that's why I said, "in general..." but it was suggested in this case when the non-JSE case worked fine. I think many fall back to JSE because it makes the case work when they haven't taken the time to do it the right way... the way a user would. In the end, many use methods that don't simulate user actions. – JeffC Feb 20 '16 at 06:44
0

You can use Actions moveToElement

Actions actions = new Actions(driver); // initialize Actions instance 
actions.moveToElement(elementToClick).performe(); // scroll the screen to make the button visible
elementToClick.click();
Guy
  • 46,488
  • 10
  • 44
  • 88
0

I just tried this and it worked... the File | Open dialog opens.

driver.findElement(By.cssSelector("div._3jk")).click();
JeffC
  • 22,180
  • 5
  • 32
  • 55
  • It works. But I am a bit concerned because this locator identifies both Add Photo/Video and Create Photo Album in Firepath. So how unique and safe would this locator be? – ilm Feb 19 '16 at 03:10
  • I don't know... I haven't tested it but you could and find out for yourself. – JeffC Feb 20 '16 at 06:45