0
votes

I have tried using Webelement to store value but facing Error like : [Below is the image of which I want to get value that is K1]

enter image description here

I am Not Getting value through Weblelement as It is displaying Error as

org.openqa.selenium.InvalidSelectorException: The given selector //div[2]/label/strong/following-sibling::text()
is either invalid or does not result in a WebElement. 

I just want to store value in variable and print it, I have tried below code but no result :

WebElement Key = driver.findElement(By.xpath("//div[2]/label/strong/following-sibling::text()")); String vs =Key.getText(); System.out.println("key Name..!!!" + vs);

Suggest Me Opinions

1
plz edit your question.... - DRPK
I don't see the <input> tag in the HTML you shared, can you update the question including the tag? You may like to expand the first div too with class=form-group - DebanjanB

1 Answers

0
votes

Try with this Xpath to obtain the WebElement:

.//strong[text()='Key']/../..//label

After that with element.getText() you should have the value : K1