Hack Forums
[.NET] [SOLVED] Webbrowser to Click Youtube Comment Box - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] [SOLVED] Webbrowser to Click Youtube Comment Box (/showthread.php?tid=5779706)

Pages: Pages 1 2


[SOLVED] Webbrowser to Click Youtube Comment Box - ThatAlbinoFrog - Jan 5, 2018

Hey guys

I'm really close to finishing my youtube mass commenter, but I'm stuck on one part, which is getting the webbrowser to click and write the comment in the comment box. 
I can't seem to use the elementID to invoke a click on it, because I'm not really sure what the ID is for the comment box.

Here's what I think I need to do - 


Code
WebBrowser1.Document.GetElementById("COMMENT BOX ID").InvokeMember("Click")
WebBrowser1.Document.GetElementById("COMMENT BOX ID").SetAttribute("Value", "This is a comment")
WebBrowser1.Document.GetElementById("SUBMIT BUTTON ID").InvokeMember("Click")


Any figuring out how to do this would be greatly appreciated. I've already successfully made the webbrowser login to youtube with that same method ^^

Thanks!

 EDIT - Solved! I needed to get the class name instead of the ID, and invoke a click on that 

Code
       Dim elements = WebBrowser1.Document.GetElementsByTagName("Div")
       For Each element As HtmlElement In elements
           If element.GetAttribute("className") = "comment-simplebox-renderer-collapsed-content" Then
               element.InvokeMember("click")
               Exit For
           End If
       Next

Thanks for all the help!

[Image: hiWljSx.png]


RE: Webbrowser to Click Youtube Comment Box - System[X] - Jan 5, 2018

(Jan 5, 2018 01:50 AM)ThatAlbinoFrog Wrote:  Hey guys

I'm really close to finishing my youtube mass commenter, but I'm stuck on one part, which is getting the webbrowser to click and write the comment in the comment box. 
I can't seem to use the elementID to invoke a click on it, because I'm not really sure what the ID is for the comment box.

Here's what I think I need to do - 


Code
WebBrowser1.Document.GetElementById("COMMENT BOX ID").InvokeMember("Click")
WebBrowser1.Document.GetElementById("COMMENT BOX ID").SetAttribute("Value", "This is a comment")
WebBrowser1.Document.GetElementById("SUBMIT BUTTON ID").InvokeMember("Click")


Any figuring out how to do this would be greatly appreciated. I've already successfully made the webbrowser login to youtube with that same method ^^

Thanks!

If you have already made a login for youtube using webbrowser then you probably know the answer i am going to give you.

Look at the source code and inspect the elements to find either id, name or even the tag of the comment box. if you then still can not figure it out post just the section of the source code for the comment box so that we can take a look and help you further.

Thanks


RE: Webbrowser to Click Youtube Comment Box - Ninja - Jan 5, 2018

(Jan 5, 2018 01:50 AM)ThatAlbinoFrog Wrote:  I can't seem to use the elementID to invoke a click on it, because I'm not really sure what the ID is for the comment box.

Uhm. Right click the comment box in your browser and click "Inspect Element" maybe?


RE: Webbrowser to Click Youtube Comment Box - ThatAlbinoFrog - Jan 5, 2018

(Jan 5, 2018 03:42 PM)System[X] Wrote:  If you have already made a login for youtube using webbrowser then you probably know the answer i am going to give you.

Look at the source code and inspect the elements to find either id, name or even the tag of the comment box. if you then still can not figure it out post just the section of the source code for the comment box so that we can take a look and help you further.

Thanks

(Jan 5, 2018 05:15 PM)Ninja Wrote:  Uhm. Right click the comment box in your browser and click "Inspect Element" maybe?

Hey, thanks for the help.  SystemX was right about me knowing what to do, but after inspecting the element and putting the ID in the code it doesn't seem to work

Here's the inspect element -
https://imgur.com/a/9scES

I've tried

WebBrowser1.Document.GetElementById("Comment-Simplebox-Create-Comment").InvokeMember("Click")

But that doesn't work. There are so many elements there that I don't know which one to use.

If someone could launch up IE and go to youtube and try to figure it out, it would be greatly appreciated.

(using IE because webbrowser uses IE, and youtube is different from IE to chrome)


RE: Webbrowser to Click Youtube Comment Box - weld - Jan 5, 2018

Damn at first I thought it was a stupid question... but now I dont know.

good luck dude :)


RE: Webbrowser to Click Youtube Comment Box - Ninja - Jan 5, 2018

(Jan 5, 2018 09:36 PM)ThatAlbinoFrog Wrote:  Hey, thanks for the help.  SystemX was right about me knowing what to do, but after inspecting the element and putting the ID in the code it doesn't seem to work

Here's the inspect element -
https://imgur.com/a/9scES

I've tried

WebBrowser1.Document.GetElementById("Comment-Simplebox-Create-Comment").InvokeMember("Click")

But that doesn't work. There are so many elements there that I don't know which one to use.

If someone could launch up IE and go to youtube and try to figure it out, it would be greatly appreciated.

(using IE because webbrowser uses IE, and youtube is different from IE to chrome)

I get "placeholder-area" before clicking, and "textarea" after clicking.


RE: Webbrowser to Click Youtube Comment Box - ThatAlbinoFrog - Jan 6, 2018

(Jan 5, 2018 10:47 PM)Ninja Wrote:  I get "placeholder-area" before clicking, and "textarea" after clicking.

WebBrowser1.Document.GetElementById("placeholder-area").InvokeMember("Click")

Returns with error - 

System.Windows.Forms.HtmlDocument.GetElementById(...) returned Nothing.


Are you using IE? Because youtube is different from IE to chrome and webbrowser uses IE


RE: Webbrowser to Click Youtube Comment Box - Ninja - Jan 6, 2018

(Jan 6, 2018 12:28 AM)ThatAlbinoFrog Wrote:  WebBrowser1.Document.GetElementById("placeholder-area").InvokeMember("Click")

Returns with error - 

System.Windows.Forms.HtmlDocument.GetElementById(...) returned Nothing.


Are you using IE? Because youtube is different from IE to chrome and webbrowser uses IE

I am using FireFox. But the HTML source should be the same. How about you print the WebBrowser source to a file and then find the element from there? Did you even try debugging your problem at all?


RE: Webbrowser to Click Youtube Comment Box - ThatAlbinoFrog - Jan 6, 2018

(Jan 6, 2018 04:40 AM)Ninja Wrote:  I am using FireFox. But the HTML source should be the same. How about you print the WebBrowser source to a file and then find the element from there? Did you even try debugging your problem at all?

I've got about 3 months of experience, so sorry for not knowing exactly what to do. How is getting the pages' source code going to help?


RE: Webbrowser to Click Youtube Comment Box - Ninja - Jan 6, 2018

(Jan 6, 2018 05:07 AM)ThatAlbinoFrog Wrote:   How is getting the pages' source code going to help?

Well, one of the possible reasons it doesn't work is that you are not selecting the right element. So to rule out this possibility, you need to make sure you have the right element and that it is present in the HTML source of the WebBrowser. So you would get the page source and check the element id there. If you get the right element ID, put it in your code and it still doesn't work then you know that your code is the problem.


RE: Webbrowser to Click Youtube Comment Box - RiperFish - Jan 6, 2018

try use this ID : "labelAndInputContainer", if not try this one :"creation-box" or "input-container"


RE: Webbrowser to Click Youtube Comment Box - ThatAlbinoFrog - Jan 6, 2018

(Jan 6, 2018 06:32 AM)RiperFish Wrote:  try use this ID : "labelAndInputContainer", if not try this one :"creation-box" or "input-container"

No luck, all return with the same sort of error -

System.Windows.Forms.HtmlDocument.GetElementById(...) returned Nothing.


RE: Webbrowser to Click Youtube Comment Box - Ninja - Jan 6, 2018

(Jan 6, 2018 07:26 AM)ThatAlbinoFrog Wrote:  No luck, all return with the same sort of error -

System.Windows.Forms.HtmlDocument.GetElementById(...) returned Nothing.

Are you blind or just stupid? I told you the solution TWICE now. You just completely ignored my post and refused to take my suggestion.

(Jan 6, 2018 07:26 AM)ThatAlbinoFrog Wrote:  System.Windows.Forms.HtmlDocument.GetElementById(...) returned Nothing.
I willl say this one more time. You keep getting errors that the element is not found. So what you need to do is get the source of the page from the webbrowser in your application to check the element id of the comment box. If you refuse to do this, and I told you this 3 times already, then you don't deserve to get more help.


RE: Webbrowser to Click Youtube Comment Box - ThatAlbinoFrog - Jan 6, 2018

(Jan 6, 2018 01:53 PM)Ninja Wrote:  Are you blind or just stupid? I told you the solution TWICE now. You just completely ignored my post and refused to take my suggestion.

I willl say this one more time. You keep getting errors that the element is not found. So what you need to do is get the source of the page from the webbrowser in your application to check the element id of the comment box. If you refuse to do this, and I told you this 3 times already, then you don't deserve to get more help.

Trying someone else's suggestion before yours is not ignoring your suggestion. I literally replied to him to tell him that it didn't work.


RE: [UNSOLVED] Webbrowser to Click Youtube Comment Box - Ranger. - Jan 6, 2018

On the new YouTube theme the comment box is loaded when you scroll the video page all the way to the bottom.
Call ScrollIntoView on the web browser's document body instance (WebBrowser.Document.Body) and pass a boolean value of false to it so that the web browser is scrolled to the end of the body. Create a while loop that waits until GetElementById returns something else other than null/Nothing.

https://msdn.microsoft.com/en-us/library/system.windows.forms.htmlelement.scrollintoview.aspx