Unable to replace value in table column

Unable to send values ​​to table column. I have different errors while I'm trying to insert a value into a column using Selenium.

  • I tried setting a new value to a table column. It shows an error because the item must be editable in order to clear it.

    WebElement.clear(); WebElement.sendKeys("value"); (or) WebElement.sendKeys(Keys.DELETE); WebElement.sendKeys("value"); 
  • Then click and edit the value.

     Actions actions = new Actions(getWebDriverEx()); WebElement TableColumn = Driver.findElement(By.id("element")); actions.moveToElement(TableColumn); actions.click().build().perform(); actions.sendKeys(Keys.BACK_SPACE+b+b); actions.sendKeys("value"); 

    The value that was transferred is not inserted in the Table column. But I can click the Tables column. Here my test passed.

  • Then he tried to set the value. It shows the error as a timeout.

      WebElement.sendKeys(Keys.DELETE); WebElement.sendKeys("15000"); 
  • Again, I used the div / span combination as XPath, and I changed the value. But this is not reflected in the table.

     JavascriptExecutor js = (JavascriptExecutor) getDriver(); js.executeScript("document.getElementById('element').innerHTML="+15000); 

Here I am not getting any errors. But the value is not reflected after saving.

I passed the item to various formats.

  • DIV // [identifier]
  • DIV // range
  • XPath
  • id (which was in the div)

HTML:

 <div id="element" class="tables_second_column"> <div class="class_name"> <div class="class_name"> <div class="class_name"><span>5000</span></div> </div> </div> </div> 
+5
source share
4 answers

thanks for your reply

It works for me using the method below.

 webElement.sendKeysByAction(value) 
0
source

According to the shared HTML the table column is within the <span> , which is inside several <div> tags. Therefore, we need to build a unique xpath to identify the WebElement and send clear() , then use sendKeys() as follows:

 driver.findElement(By.xpath("//div[@id='element']/div[@class='class_name']/div[@class='class_name']/div[@class='class_name']/span[text()='5000']")).clear(); driver.findElement(By.xpath("//div[@id='element']/div[@class='class_name']/div[@class='class_name']/div[@class='class_name']/span[text()='5000']")).sendKeys("15000"); 

Update

As you mentioned Text which was passed in the span is not predictable , we just omit the sentence [text()='5000'] . Since you provided an HTML sample with a sample classnames , I built an almost absolute xpath . So our code will be:

 driver.findElement(By.xpath("//div[@id='element']/div[@class='class_name']/div[@class='class_name']/div[@class='class_name']/span")).clear(); driver.findElement(By.xpath("//div[@id='element']/div[@class='class_name']/div[@class='class_name']/div[@class='class_name']/span")).sendKeys("15000"); 
+1
source

Try the following and it works for me:

 js = "document.querySelector('#element .class_name .class_name .class_name>span').innerHTML = '15000';" driver.execute_script(js) 

Hope this helps you!

+1
source

That should be enough

 WebElement textBox = driver.findElement(By.xpath("//span[text()='5000']")); textBox.clear(); textBox.sendKeys(""); textBox.sendKeys("15000"); 

I am sending blank space to receive a text box as soon as the DOM may not immediately reflect, since this element is a quiet nested.

+1
source

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


All Articles