SimpleBrowserDotNet / SimpleBrowser

A flexible and intuitive web browser engine designed for automation tasks. Built on .NET Standard 2.1.
Other
362 stars 105 forks source link

How to locate a textarea with no atributes #252

Closed YouTrade closed 4 years ago

YouTrade commented 4 years ago

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

image

kevingy commented 4 years ago

@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 commented 4 years ago

Dear Kevin

Thank you

One more question please ... how to populate this textarea in order to send information written inside this.

Best Regards

Marcelo

Sent from my YouTrade iPhone

Em 2 de mai de 2020, à(s) 11:05, Kevin Yochum notifications@github.com escreveu:

 @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

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

kevingy commented 4 years ago

@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";
}
YouTrade commented 4 years ago

Thank you very much. Please accept my apologies for the simple question.

Sent from my YouTrade iPhone

Em 2 de mai de 2020, à(s) 11:53, Kevin Yochum notifications@github.com escreveu:

 @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"; } — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

YouTrade commented 4 years ago

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

kevingy commented 4 years ago

@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.

YouTrade commented 4 years ago

Thank you very much.

Keep you posted.

Obrigado

Em 2020-05-02 13:59, Kevin Yochum escreveu:

@YouTrade [1] 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.

-- You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub [2], or unsubscribe [3].

Links:

[1] https://github.com/YouTrade [2] https://github.com/SimpleBrowserDotNet/SimpleBrowser/issues/252#issuecomment-622983470 [3] https://github.com/notifications/unsubscribe-auth/AGIYB3OJBGWEI6TNTOETPNLRPRGNLANCNFSM4MXTCBBA