I am having a problem sending the ENTER key using selenium. I've tried a variety of ways but it seems none of them are working.
Element code :
<span _ngcontent -c10>elementName</span>
After choosing the element, the element is changed to
<input _ngcontent -c10 class="title-input" type="text">
-I have made sure I have the right element.
-Whenever there's a "RETURN" I also tried using "ENTER".
Things I tried:
--1--
textBox.click();
textBox.sendKeys(Keys.RETURN);
--2--
Actions actions = new Actions(driver);
actions.click(textBox);
actions.sendKeys(textBox, Keys.RETURN);
--3--
driver.getKeyBoard().pressKey(Keys.RETURN);
Thread.sleep(100);
driver.getKeyBoard().releaseKey(Keys.RETURN);
--4--
Robot r = new Robot();
textBox.click();
r.keyPress(KeyEvent.VK_ENTER);
Thread.sleep(100);
r.keyRelease(KeyEvent.VK_ENTER);
Any help is appreciated! Thanks!
A bit more of outerHTML as DebanjanB requested :
<div _ngcontent-c6 class="tab clicked" style="width: 50%;">
<tab-header _ngcontent-c6 _nghost-c10>
<span _ngcontent-c10 class="tab-header-name">
<!---->
<input _ngcontent-c10 class="title-input" type="text"> == $0
<!---->
</span>
<!---->
<span _ngcontent -c10 id="delete-tab" class="can-delete">x</span>
<!---->
<!---->
<img _ngcontent-c10 id="not-pin-tab" src="assets/images/notPin.png">
<tab-header>
</div>
As you mentioned that Keys.RETURN didn't work here are a few alternatives :
As the WebElement is a Angular Element you have to induce WebDriverWait for the element to be clickable as follows :
WebElement my_element = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(textBox));
Next you can attempt for the click() and sending Keys.RETURN as follows :
my_element.click()
my_element.sendKeys(Keys.RETURN);
You can also try for Keys.Enter as an alternative as follows :
my_element.click()
my_element.sendKeys(Keys.ENTER);
You can find a detailed discussion in What is the best practice to simulate an ENTER or RETURN using Selenium WebDriver
Incase the WebElement is with in a <form> tag you can also try to invoke submit() as follows :
my_element.click()
my_element.submit();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With