0

In the attached screenshot I want to read the value of title which is 'Title_6jOa' But I'm unable to locate the element because text value is not present in highlighted area.

Any solution please.? enter image description here

Subburaj
  • 2,294
  • 3
  • 20
  • 37
Kms
  • 1,082
  • 2
  • 11
  • 27
  • By any chance can we see the site? – Deb May 23 '18 at 05:28
  • @kumar, I have assumed you have tried with getText() method.Please check the below answer for the details – Subburaj May 23 '18 at 06:08
  • Please read why a [screenshot of HTML or code or error is a bad idea](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors). Consider updating the Question with formatted text based relevant HTML, code trials and error stack trace. – undetected Selenium May 23 '18 at 06:15

3 Answers3

1

You should be able to locate the field by the class of the field, a CSS selector could be .x-frs-id-ivnt_Title

Then for reading the text that is typed into the field, findElement(By.cssSelector(".x-frs-id-ivnt_Title")).getAttribute("value")

If the css selector .x-frs-id-ivnt_Title can't find the expected text box, try below xpath:

findElement(By.xpath("//tr[td[contains(., 'Title')]]/td/input")).getAttribute("value")

Please check the CSS selector and xpath manually in browser DevTool before change code.

yong
  • 13,357
  • 1
  • 16
  • 27
Pieter A
  • 166
  • 3
  • I already tried that one but it is returning no value. Because in the highlighted area value it self is not present it is showing ==$0 – Kms May 23 '18 at 05:20
  • Please add the exact code you are using and the exception you get when you execute it in the description of your question. – Pieter A May 23 '18 at 05:23
  • Try the css locator `.x-frs-id-ivnt_Title` in browser' DevTool manually, to see the first matched element is the text box you wanted. – yong May 23 '18 at 05:27
0

Input Field Text values will not be be persisted in the Input Tag in Dev Tool.So,we cannot not use getText() Method and it can be extracted using the getAttribute() method as below or JavaScriptExecutor can be used (Using Selenium Web Driver to retrieve value of a HTML input)

Steps:

  1. Identity the text field Web Element using any one of the unique locator
  2. Use the getAttribute Method to get the value

Code :

WebElement titleInputElement=driver.findElement(By.xpath("//input[contains(@class,'x-frs-id-ivnt_Title')]"));
String value=titleInputElement.getAttribute("value");
Subburaj
  • 2,294
  • 3
  • 20
  • 37
0

@yong , @Subburaj Sorry tried yours way too, but getting no value.

Getting the value in below way perfectly.

Steps:

  1. Double click in the text field. To get text selected. enter image description here

  2. Then copy the text to clipboard using Keyboard key ctrl+c Copy the text

  3. And Then the final step is reading the text from clipboard by below line of code in c#.

string clipboardExpectedText = System.Windows.Forms.Clipboard.GetText(System.Windows.Forms.TextDataFormat.Text);

Kms
  • 1,082
  • 2
  • 11
  • 27