Results 1 to 17 of 17

Thread: [RESOLVED] simulate mouse r/click,Copy & paste...

  1. #1

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Resolved [RESOLVED] simulate mouse r/click,Copy & paste...

    it is an unusual question please be patient

    My series of intentions;

    (1) open a web page
    (2) select all contents, as same as -> edit->select all
    (3) Copy the contents to a excel file (Say for ex into CELL A1)
    (4) clear the clipboard
    (5) open another web page & continue

    basic ideas please?

    Sorry if my question irritates you please
    Last edited by make me rain; Feb 15th, 2011 at 10:38 AM. Reason: missing information
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  2. #2
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,158

    Re: simulate mouse r/click,Copy & paste...

    Basically you need to open the webpage using an WebBrowser Control, then you can access the various element of the webpage and get the data of those elements
    This Link Should help you

  3. #3
    Fanatic Member BlindSniper's Avatar
    Join Date
    Jan 2011
    Location
    South Africa
    Posts
    865

    Re: simulate mouse r/click,Copy & paste...

    If you are doing this with a webbrowser you can use sendkeys to select all and copy it to the clipboard
    Code:
     
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            WebBrowser1.Navigate("A Url")
        End Sub
    
        Private Sub WebBrowser1_Navigated(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatedEventArgs) Handles WebBrowser1.Navigated
    
    
                WebBrowser1.Focus()
                SendKeys.SendWait("^a")
                SendKeys.SendWait("^c")
           
    
        End Sub
    Or you could just get the html source from the webbrowser document
    Last edited by BlindSniper; Feb 15th, 2011 at 11:06 AM.

    Useful CodeBank Entries of mine
    Expand Function
    Code Compiler
    Sudoku Solver
    HotKeyHandler Class

    Read this to get Effective help on VBForums
    Hitchhiker's Guide to Getting Help at VBF

  4. #4

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Wink Re: simulate mouse r/click,Copy & paste...

    thank you ashish & sniper
    so far i have not done any work on webbrowser control
    let me try
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  5. #5

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Question Re: simulate mouse r/click,Copy & paste...

    code to works some extent, but next page not loading ? !
    further advise please

    vb.net Code:
    1. Imports System.Web
    2. Public Class web
    3.     Inherits System.Windows.Forms.Form
    4.  
    5.  
    6.     Private Sub web_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    7.  
    8.         With Me.WebBrowser1
    9.             .Navigate("http://203.176.113.112/CMSREPORT/JSP/nonloginreports/CMSAnalysisStatistics.do?hmode=home")
    10.         End With
    11.  
    12.     End Sub
    13.  
    14.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    15.  
    16.         With Me.WebBrowser1
    17.  
    18.             Me.WebBrowser1.Document.Forms.Item(0).DomElement(1).value = "UBL1425"
    19.             'in fact i want to si mulate click go button ( i mean label)
    20.             Me.WebBrowser1.Document.Forms(0).InvokeMember("submit")
    21.             'why yhe next page is not loading here ?? !!!!
    22.             'but if i click manually on the go label next page is loading
    23.         End With
    24.     End Sub
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  6. #6
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: simulate mouse r/click,Copy & paste...

    Try this:
    vb.net Code:
    1. Public Class web
    2.     Private submitted As Boolean = False
    3.  
    4.     Private Sub web_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    5.         WebBrowser1.Navigate("http://203.176.113.112/CMSREPORT/JSP/nonloginreports/CMSAnalysisStatistics.do?hmode=home")
    6.     End Sub
    7.  
    8.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    9.         '' fill textbox and click button
    10.         Dim crewId As HtmlElement = WebBrowser1.Document.All("crewId")
    11.         crewId.SetAttribute("value", "UBL1425")
    12.         crewId.NextSibling.InvokeMember("click")
    13.         submitted = True
    14.     End Sub
    15.  
    16.     Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
    17.         '' write to text file
    18.         If submitted AndAlso WebBrowser1.ReadyState <> WebBrowserReadyState.Complete Then Exit Sub
    19.         Dim pageContents As String = WebBrowser1.Document.Body.InnerText
    20.         IO.File.WriteAllText("C:\Temp\test.CSV", pageContents)
    21.     End Sub
    22. End Class
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  7. #7

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Wink Re: simulate mouse r/click,Copy & paste...

    pradeep ji thank you

    in fact i am going through http://msdn.microsoft.com/en-us/libr...mlelement.aspx here, very wast i am not confident of finishing it practically.

    your code works fine.
    kindly advise me , in the next page opens there, it gives me options with radio buttons & one button

    if you don't mind can you please advise further to load the next page with options.
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  8. #8
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: simulate mouse r/click,Copy & paste...

    I see 5 radiobuttons and 2 command buttons.

    Which option you want to select and which button to click?
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  9. #9
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: simulate mouse r/click,Copy & paste...

    vb.net Code:
    1. Public Class web
    2.     Private stage As Integer = 0
    3.  
    4.     Private Sub web_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    5.         WebBrowser1.Navigate("http://203.176.113.112/CMSREPORT/JSP/nonloginreports/CMSAnalysisStatistics.do?hmode=home")
    6.     End Sub
    7.  
    8.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    9.         '' fill textbox and click button
    10.         stage = 1
    11.         Dim crewId As HtmlElement = WebBrowser1.Document.All("crewId")
    12.         crewId.SetAttribute("value", "UBL1425")
    13.         crewId.NextSibling.InvokeMember("click")
    14.     End Sub
    15.  
    16.     Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
    17.         If WebBrowser1.ReadyState <> WebBrowserReadyState.Complete Then Exit Sub
    18.         Select Case stage
    19.             Case 1
    20.                 '' write to text file
    21.                 Dim pageContents As String = WebBrowser1.Document.Body.InnerText
    22.                 IO.File.WriteAllText("C:\Temp\test.CSV", pageContents)
    23.  
    24.                 '' proceed to next stage
    25.                 stage = 2
    26.                 Dim myElement As HtmlElement
    27.                 myElement = GetInputControl("durationtype", "FORTNIGHT") ' set values
    28.                 myElement.InvokeMember("click")
    29.                 myElement = GetInputControl("currentSlot", "CURRENT") ' set values
    30.                 myElement.InvokeMember("click")
    31.                 myElement = GetInputControl("submit", "CrewRunDetails")  ' click button
    32.                 myElement.InvokeMember("click")
    33.  
    34.             Case 2
    35.                 '' you will get the 2nd page here..
    36.                 '' do whatever you want to with it.
    37.                 MsgBox(WebBrowser1.Document.Body.InnerText)
    38.  
    39.         End Select
    40.  
    41.     End Sub
    42.  
    43.     Private Function GetInputControl(ByVal name As String, ByVal value As String) As HtmlElement
    44.         Return (From element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("INPUT") _
    45.                 Where element.Name = name AndAlso element.GetAttribute("value") = value).FirstOrDefault
    46.     End Function
    47. End Class
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  10. #10

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Smile Re: simulate mouse r/click,Copy & paste...

    pradeep ji, thank you & sorry i am troubling you too much

    is it possible to save the contents of the table which opens after the radio + command button click. in to a database,

    what i tried was,
    save all the employee records
    contents of the web page table
    ( crewid,crewname,slot on the top )
    and his relative rows in the table in to a MySQL table.

    hence i thought of saving the final web page contents in to an excel &
    from there in to an database,because it was easy for me to pickup crew name,id, etc with a cell reference

    but this activity is taking huge time,space...
    and appears to be derailed from the track

    kindly advise please
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  11. #11
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: simulate mouse r/click,Copy & paste...

    So what code do you have till now and what specifically is not working?
    You should be able to easily modify post #9 to your needs.

    &#160;
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  12. #12

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Smile Re: simulate mouse r/click,Copy & paste...

    fine

    is it possible to pick the data in
    web page table rows
    to
    database fields directly.

    instead of saving the page contents into .csv file & from there in to an database
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  13. #13
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: simulate mouse r/click,Copy & paste...

    There is hardly anything you can think of logically but not able to program it.

    So what code do you have till now? Which database?
    If you provide clear description of your problem and what you have tried till now, there are many here who would be able to help you out with your problems.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  14. #14

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Wink Re: simulate mouse r/click,Copy & paste...

    So for is good,

    ultimate the task is :
    automating the
    importing of data basing on crewID from the web page into MySQL data base.

    So for covered:
    Opened web page and saved the data into .xls file

    what i would like to do now is:
    instead of saving pagecontent or innerHTML of the web page as an .xls file & then read from .xls file in to MySQL database , i want to save the read & save the data in to the database.

    i will post the code now sir...
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  15. #15

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Wink Re: simulate mouse r/click,Copy & paste...

    Task:
    reading from the file saved as .xls
    **************************
    way 1.

    i can't connect to the file file saved as xls. bug i will get is
    "External table is not in the expected format."

    this case was clarified by jmc earlier why i can't connect.
    vb.net Code:
    1. Dim ExlCnn As New OleDb.OleDbConnection
    2.         Dim ExlFilepath As String = "e:\Impo.xls"
    3.         Dim ExlCnns As String = _
    4.         "Provider=Microsoft.ACE.OLEDB.12.0;" _
    5.         & " Data Source=" & ExlFilepath _
    6.         & ";Extended Properties='Excel 12.0;HDR=NO';"
    7.  
    8.         ExlCnn.ConnectionString = ExlCnns
    9.  
    10.         If ExlCnn.State <> ConnectionState.Open Then
    11.             ExlCnn.Open()
    12.         End If
    13.         MessageBox.Show(ExlCnn.State)

    way 2.

    'i must open the saved excel file
    'read / loop through the required data & then save the values into MySQL
    'This process is slow,
    '**** HENCE I WANT TO READ DATA FROM THE WEB PAGE IT SELF*******

    vb.net Code:
    1. Dim ExlFilepath As String = "e:\Impo.xls"
    2.         Dim Exl As New Excel.Application
    3.         Dim Exl_Wb As Excel.Workbook
    4.         Dim Exl_Sheet As Excel.Worksheet
    5.  
    6.         Exl_Wb = Exl.Workbooks.Add
    7.         Exl_Sheet = Exl_Wb.Worksheets(1)
    8.  
    9.         Exl.Workbooks.Open(ExlFilepath)
    10.  
    11.         'here i am reading the field values
    12.         With Exl_Sheet
    13.             Dim CrewId As String = .Range("b5").Cells.Value
    14.             Dim CrewName As String = .Range("b6").Cells.Value
    15.             Dim Slot As String = .Range("e4").Cells.Value
    16.             Dim PFnumber As String = .Range("d6").Cells.Value
    17.         End With
    18.  
    19.         'update the primary crew data
    20.         ' Call uPdateBasicCrewData(CrewID, cREWNAME, SloT, PFnumber)
    21.  
    22.         Exl_Wb.Close()
    23.         Exl.Quit()
    24.  
    25.         Exl_Sheet = Nothing
    26.         Exl_Wb = Nothing
    27.         Exl = Nothing

    Further advise please sir
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  16. #16
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: simulate mouse r/click,Copy & paste...

    You don't need any excel file or any other file as an intermediate. You can always access the data directly from the html page.

    vb.net Code:
    1. Case 2
    2.         '' you will get the 2nd page here..
    3.  
    4.         Dim htmlTable As HtmlElement = WebBrowser1.Document.GetElementsByTagName("TABLE")(5)
    5.         Dim myList = From tr In htmlTable.GetElementsByTagName("TR") _
    6.                      Let td As HtmlElementCollection = tr.GetElementsByTagName("TD") _
    7.                      Where td.Count = 16 _
    8.                      Select New With {.Date = td(0).InnerText, _
    9.                                       .Rest = td(1).InnerText, _
    10.                                       .SignOnTime = td(2).InnerText, _
    11.                                       .SignOnFrom = td(3).InnerText, _
    12.                                       .Train = td(4).InnerText _
    13.                                               ' -- add other fields in the same way --
    14.                                      }
    15.         ' Now you have everything in myList
    16.         ' You can access the items from this list and fill into your datatable or whatever you have
    17.  
    18.         End Select
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  17. #17

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Smile Re: simulate mouse r/click,Copy & paste...

    vow........
    great & thanks
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width