0
votes

I have used getText(); but not working please help me out

Text Box 1: I need to get the value from this text box.

String value = driver.findElement(By.xpath("html/body/div[5]/div/div/div/div/div[2]/div/div[1]/input")).getText();

Text Box 2: I wanted to put it here but value is not coming here.

driver.findElement(By.xpath("html/body/div[1]/div/div[2]/div/div/div/div[2]/div[1]/div[1]/form/div/input")).sendKeys(value);

Any help is appreciated, thanks in advance.

2
POST the html code for that selement - NarendraR
do you want to text of input tag's placeholder ? - NarendraR

2 Answers

1
votes

getText() is not working in many occasions. You can use .getAttribute("value") to get the text.

0
votes

Make sure your first text box is not inside an iframe and is visible accessible. If it is, then its possible that your xpath might not be correct. Instead of using system generated paths or the full path , try using css and other locators to identify the element. What browser are you using ? IE is sometimes slow to respond to the sendkeys method. Use chrome instead and if that is not an option, try copy pasting using the below code

.sendKeys(Keys.CONTROL,"v");


public void copyToClipBoard(String data) {
    // TODO Auto-generated method stub
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Clipboard clipboard = toolkit.getSystemClipboard();
    StringSelection selectedData = new StringSelection(data);
    clipboard.setContents(selectedData, null);
}