How to resolve org.openqa.selenium.WebDriverException?

对着背影说爱祢 提交于 2020-01-02 18:35:20

问题


I am writing an automated test and want to report bugs, if occur, directly in the repo at GitHub. The step which fails in my program is the Submit new issue button from GitHub Issue Tracker.

Here is the code:

WebElement sendIssue = driver.findElement(By.xpath("/html/body/div[5]/div/div/div[2]/div[1]/div/form/div[2]/div[1]/div/div/div[3]/button"));

sendIssue.click();

And the exception:

org.openqa.selenium.WebDriverException: Element is not clickable at point (883, 547.7999877929688). Other element would receive the click: div class="modal-backdrop">

The following command also does not work:

((JavascriptExecutor) driver).executeScript("arguments[0].click();", sendIssue);

How can I make it clickable? Is there any other way by which I can resolve this issue?

enter image description here


回答1:


This is happening because when selenium is trying to click ,the desired element is not clickable.

You have to make sure that the Xpath provided by you is absolutely right.If you are sure about the Xpath then try the following

replace

WebElement sendIssue = driver.findElement(By.xpath("/html/body/div[5]/div/div/div[2]/div[1]/div/form/div[2]/div[1]/div/div/div[3]/button"));

sendIssue.click();

with

WebElement sendIssue =(WebElement)new WebDriverWait(DRIVER,10).until(ExpectedConditions.elementToBeClickable(By.xpath("/html/body/div[5]/div/div/div[2]/div[1]/div/form/div[2]/div[1]/div/div/div[3]/button")));
sendIssue.click();

If that doesn't work ,You will get an Timeout exception, In that case try incaresing the timeout amount from 10 to 20.

If it still doesn't work please post a screenshot of the HTML.

You need to write something in the issue title and description to make the issue clickable are you sure you are not making that mistake of clicking the button without writing anything in those places I am adding screenshot for your convenience.




回答2:


Selenium Webdriver introduced in a previous version (v2.48) a new behavior that prevent clicks on elements that may be overlapped for something else (a fixed header or footer - for example) or may not be at your viewport (visible area of the webpage within the browser window). You can see the debate here.

To solve this you will need to scroll (up or down) to the element you're trying to click.

One approach would be something like this post:

Page scroll up or down in Selenium WebDriver (Selenium 2) using java

Another, and maybe more reasonable, way to create a issue on Github, would be using their API. Maybe it would be good to check out!

Github API - Issues

Gook luck.



来源:https://stackoverflow.com/questions/37205957/how-to-resolve-org-openqa-selenium-webdriverexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!