# Best keyword to tab off an element

**URL:** <https://forum.robotframework.org/t/best-keyword-to-tab-off-an-element/4533>\
**Category:** Libraries\
**Created:** [17 August 2022 22:00 UTC](https://forum.robotframework.org/t/best-keyword-to-tab-off-an-element/4533 "2022-08-17T22:00:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bweston](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/bweston/32/1298_2.png) [@bweston](https://forum.robotframework.org/u/bweston)\
**Post date:** [17 August 2022 22:00 UTC](https://forum.robotframework.org/t/best-keyword-to-tab-off-an-element/4533/1 "2022-08-17T22:00:46Z")

</div>

I have a drop down combo element that I need to focus on and tab off in order to fire a validation message. I cannot use Press Keys or Click Element as it will invoke the list and I cannot use Mouse Over since the only argument is location. Does anyone have suggestions to handle this scenario?

Example:  
 ![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/9/98e30784afc94cb5efba8227e91e3d9deb02b018.png)

---

<div class="post-metadata">

**Author:** ![tomas14](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/tomas14/32/1789_2.png) [@tomas14](https://forum.robotframework.org/u/tomas14)\
**Post date:** [22 August 2022 08:48 UTC](https://forum.robotframework.org/t/best-keyword-to-tab-off-an-element/4533/2 "2022-08-22T08:48:58Z")

</div>

I also want some TAB-ing on my website and have problems with using press keys

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [22 August 2022 08:54 UTC](https://forum.robotframework.org/t/best-keyword-to-tab-off-an-element/4533/3 "2022-08-22T08:54:54Z")

</div>

My first question is how are you achieving this manually?

Once you know this you can plan a possible approach that can simulate the same manual sequence.

Dave.

---

<div class="post-metadata">

**Author:** ![lslackware1](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/lslackware1/32/1815_2.png) [@lslackware1](https://forum.robotframework.org/u/lslackware1)\
**Post date:** [22 August 2022 10:41 UTC](https://forum.robotframework.org/t/best-keyword-to-tab-off-an-element/4533/4 "2022-08-22T10:41:02Z")

</div>

try some javascript, perhaps that could help there

---

<div class="post-metadata">

**Author:** ![bweston](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/bweston/32/1298_2.png) [@bweston](https://forum.robotframework.org/u/bweston)\
**Post date:** [22 August 2022 13:23 UTC](https://forum.robotframework.org/t/best-keyword-to-tab-off-an-element/4533/5 "2022-08-22T13:23:11Z")

</div>

I tab to the element from a different element and then tab off the element. But I do not wish to use that as my method. The reason is because I want to reuse the same user defined keyword in other tests and the tab order will be different.

Is there a keyword that allows the use of tabbing without using Press Keys or Click Element?

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [23 August 2022 00:51 UTC](https://forum.robotframework.org/t/best-keyword-to-tab-off-an-element/4533/6 "2022-08-23T00:51:05Z")

</div>

OK so what I suggest is

- first navigate to the element before the “drop down combo element” in the tab order with a click or other action that gets you there.
- Use [Press Keys](https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html#Press%20Keys) with a locator of `None` and the `TAB` key. (this sends the Tab key to the browser window not the element, hopefully this will simulate what you are doing manually)
- Use [Press Keys](https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html#Press%20Keys) with a locator of `None` and the `TAB` key again to navigate off the “drop down combo element”
- verify the error message

You might also want to add a [Element Should Be Focused](https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html#Element%20Should%20Be%20Focused) step between the `Press Keys` steps to verify you went to the right field (in case the tab order changed in some future release)

Dave.

---

<div class="post-metadata">

**Author:** ![bweston](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/bweston/32/1298_2.png) [@bweston](https://forum.robotframework.org/u/bweston)\
**Post date:** [24 August 2022 16:34 UTC](https://forum.robotframework.org/t/best-keyword-to-tab-off-an-element/4533/7 "2022-08-24T16:34:41Z")

</div>

This does solve the noted problem - thanks, but it exposes a more complex issue that I am trying to resolve.

The field in question “Organization” occurs in several different forms within the application. My goal was to setup a single kwarg within the test that can be repeated for every form. The issue is the field is not placed in the same place in all of the different forms.

This appears to leave me with two choices: Create a kwarg and unique keywords for each form to handle the Press Keys (NONE TAB) or find a keyword that allows me to have focus on the field (drop down combo) without invoking the list. The latter is what I was originally trying to handle.

Example that I am trying to avoid:  
Validate Organization is Required Form A  
Validate Organization is Required Form B  
Validate Organization is Required Form C

@lslackware1 said to try some javascript, but I am not familiar with java so have not found a proper solution. If anyone has a java suggestion please advise.

I have tried the following but now how to tab off without invoking the list:  
Execute Javascript document.getElementById${ORGANIZATION}.focus();

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [24 August 2022 22:40 UTC](https://forum.robotframework.org/t/best-keyword-to-tab-off-an-element/4533/8 "2022-08-24T22:40:43Z")

</div>

Maybe try a keyword for validating the field that takes an argument for the previous field?

Something like:

```python
Validate Organization is Required
    [Arguments] ${prev_fld}
    Click ${prev_fld}
    Press Keys None TAB
    Press Keys None TAB
    # validate error

```

Then in you test case for Form A

```python
    Validate Organization is Required //locator/for/prev/fielda

```

Then in you test case for Form B

```python
    Validate Organization is Required css: fieldb

```

etc
