Selenium: enter text in div using xpath

In selenium for input, we can enter a value similar to:

WebElement inputBox = driver.findElement(By.xpath(xpath))); inputBox.sendKeys("abc"); 

but on one webpage I have one button after clicking on it to get one div, which I have to enter through selenium, I get xpath for this div, like

 WebElement inputDiv = driver.findElement(By.xpath("//div[contains(@class,'x-grid3-cell-inner')]")); inputDiv.sendKeys("abc"); //This is not working 

using xpath, I get a div, but how to enter text in that using xpath?

Html after adding text manually:

 <div class="x-grid3-cell-inner">ty</div> 

The div into which I should enter the text includes:

 <div class="x-grid3-cell-inner" /> 
+2
source share
2 answers

You can update div text using javascript

 JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("document.getElementById('Div_Id').innerHTML="+ DesiredText); 

Using XPATH in JavaScript

 JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("document.evaluate(xpathExpresion, document, null, 9, null).singleNodeValue.innerHTML="+ DesiredText); 

Link

+3
source

You cannot edit this div using the submit keys, as it does not have input to send. Instead, try changing the div text box.

0
source

Source: https://habr.com/ru/post/1273548/


All Articles