SimpleBrowserDotNet/SimpleBrowser

How to locate a textarea with no atributes

YouTrade opened this issue · 7 comments

Can someone please help me find the right syntax to find and populate this text area that has no attributes?

image

@YouTrade I don't understand your question entirely. The highlighted text area does have attributes, namely rows and style. Using those, you can do any of the following:

Browser browser = new Browser();
HtmlResult result = null;
result = browser.Find("textarea", new { rows = "1" });
result = browser.Find("textarea", new { style = "height: 54px;" });
result = browser.Find(ElementType.TextField, new { rows = "1" });
result = browser.Find(ElementType.TextField, new { style = "height: 54px;" });
result = browser.Find(ElementType.TextField, "rows", "1");
result = browser.Find(ElementType.TextField, "style", "height: 54px;");

The result variable should hold the textarea.

If you don't want to use the rows or style attributes, you can always use an XPath select:

result = browser.Select("//div[contains(@class, 'fileWrapper ico')]/textarea");

Kevin

@YouTrade

It should be as simple as setting the Value property:

Browser browser = new Browser();
HtmlResult result = browser.Find("textarea", new { rows = "1" });
if(result.Exists)
{
   result.Value = "some text";
}

One more question please.
What is the difference between these 2 ?

result = browser.Find(ElementType.TextField, new { style = "height: 54px;" });
result = browser.Find(ElementType.TextField, "style", "height: 54px;");

Thank you again please

@YouTrade In most cases, there is no difference. I would have to look a the code, but many of the methods rework the parameters to call the same Find method.

Sometimes, bad HTML can cause the parser will generate unexpected XDocuments. Sometimes different find methods are needed to get to the HtmlResult desired.