How to simulate mouse click on blank area in website by Selenium IDE?
Asked Answered
R

11

23

I want to perform a mouse click on a blank area outside a form in order to wake up the data traffic in some websites by Selenium IDE. Any ideas?

I've tried to do click by x,y but it doesn't effective for my test case. The scenario is below:

  1. fill in the email field
  2. click outside the form in order to make the client send a data request to the server to check if this email already exists in the DB and then it does auto-complete and enables the continue button.
Rayford answered 15/1, 2015 at 14:50 Comment(0)
T
12

The best solution is to just use the keyboard TAB key by executing the following statement.

element.sendKeys(Keys.TAB);

It will focus the next element - thus out of the field - and you will get your desired result.

Toon answered 27/7, 2019 at 20:23 Comment(0)
S
10

You can use the command:

driver.findElement(By.xpath("//html")).click();

But sometimes it doesnt take blank spaces,

In such cases, use:

driver.get("//html");
Saker answered 12/2, 2016 at 6:28 Comment(2)
This does not work, at least in chrome. Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.Dillondillow
Doesn't work Failure reason: unknown error: unhandled inspector error: {"code":-32603,"message":"Cannot navigate to invalid URL"}Kummerbund
C
7

'html' is a special element, what you want is 'body' (the first DOM element that is 'visible')

so please use the following (tested with Chrome confirme working with no problem):

python example driver.find_element_by_xpath("//body").click()

Conflict answered 23/4, 2019 at 17:21 Comment(0)
T
4

You can click to outside of element using Actions

 public void clickOutside() {
            Actions action = new Actions(driver);
            action.moveByOffset(0, 0).click().build().perform();
        }
Theism answered 24/6, 2020 at 15:27 Comment(0)
S
2

Just click on another element on the page you are sure is present.

Browser.Driver.FindElement(By.Id("testtest123")).Click();

Another solution may be to invoke javascript removing the focus from that email field, it depends on the trigger you have set for the ajax to trigger.

Shrine answered 15/1, 2015 at 15:3 Comment(3)
Thanks Alex, but i don't use the selenium web driver, only by the IDE 2.8.0. Do you have another idea? something can use by the selenium IDE commands or by external javascript?Rayford
What is the trigger for the ajax? If it is called when your text field loses focus just run javascript with focus on another element.Shrine
var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-20992974-4']); _gaq.push(['_set', 'title', 'Clients Portal']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();Rayford
S
2

I need to click in a blank area in the react code.

The below code is fixed my issue.

 driver.FindElement(By.XPath("//body")).Click();
Scansion answered 12/3, 2020 at 5:54 Comment(0)
E
1

Once email is filled, to click blank area, use this command.

driver.findElement(By.xpath("//html")).click();

It will click blank area.

Electroacoustics answered 8/2, 2015 at 17:41 Comment(1)
This does not work, at least in chrome. Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.Dillondillow
G
1
public void clickOutside() {
            Actions action = new Actions(driver);
            action.moveByOffset(0, 0).click().build().perform();
        }

This is the perfect solution for this problem.

Grip answered 13/5, 2021 at 10:25 Comment(1)
This post duplicates answer by Norayr Sargsyan. Could you please make this a comment under the original answer instead of having it as a duplicate answer in the same thread?Hawkbill
C
0

I hope it still can help people, so i have the answer =) Selenium always throws exceptions on simple click if dropdown, field or whatever makes other buttons inactive. The way out for me was to use actions with pause. Here are some code rows from my example:

Actions actions = new Actions(driver);
actions.moveToElement(driver.findElement(By.xpath("your path")))
       .click().pause('your amount of milliseconds').click().build().perform();

Wrap it into some function and there you go, you have a new clicker.

Carilla answered 7/3, 2019 at 13:42 Comment(0)
A
0

None of them worked for me. I solved the problem as below;

   WebElement el = driver.findElement(By.xpath("//html"));
   el.sendKeys(Keys.TAB);
Anatase answered 16/12, 2021 at 9:23 Comment(0)
F
-1

Below code worked fine for me.

Actions action = new Actions(driver);
action.moveByOffset(0, 0).click().build().perform();
Faddish answered 23/6, 2022 at 8:7 Comment(1)
Could you please make this a comment under the original answer instead of having it as a duplicate answer in the same thread? I guess this post got negative vote because it duplicated the answer by Norayr SargsyanHawkbill

© 2022 - 2024 — McMap. All rights reserved.