Click here to Skip to main content
15,893,644 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)

Basic Information


I have this software that I am developing for my personal use because im using it as a way to learn Selenium (By trial and error and so far I know the basics because I already went through it)

What the software does


It will analyze the top 5 most active stocks from a list on the website and print it out on to the software (Pretty simple right?)

The Issue



At this moment I've made it so it pulls a name & the percentage of top item from the list on this website (which used to be the top one) but then it changed to the 3rd one and what it does when I actually press the button is (as I just explained) it pulls the third option which is the one that used to be the first one


What I WOULD like it to do



I would need the correct TagName or the CssSelector which shows whats in the list from 1-5 EVEN if it changes, I would like it to change when the website changes

Example



I press the button (label11_Click) (Sorry for the bad naming on my part)
It shows the top 5 items
I close the app and wait 24 hours
The list changes on the website
I reopen the application after 24 hours
I press the same button (label11_Click)
it shows the new top 5 items



My Work At the moment


Website: TradingView: Free Stock Charts and Forex Charts Online.[^]
List: This List Is Being Showed On The Website[^]
The Inspector[^]


My Code

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.PhantomJS;

namespace TestingUI
{
    public partial class mainForm : Form
    {

        
        Timer t = new Timer();


        public mainForm()
        {
            InitializeComponent();
        }

        int mouseX = 0, mouseY = 0;
        bool mouseDown;



             private void viewDash(object sender, MouseEventArgs e)
        {
            
        }


        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            mouseDown = true;
        }

        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            if (mouseDown)
            {
                mouseX = MousePosition.X - 200;
                mouseY = MousePosition.Y - 40;

                this.SetDesktopLocation(mouseX, mouseY);

            }

        }

        private void panel1_MouseUp(object sender, MouseEventArgs e)
        {
            mouseDown = false;
        }

        private void leftsidePanel_Paint(object sender, PaintEventArgs e)
        {





        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //Timer Interval
            t.Interval = 1000; //Milliseconds

            t.Tick += new EventHandler(this.t_Tick);

            //start timer when form loads
            t.Start();

        }


        //Timer eventhandeler

        private void t_Tick(object sender, EventArgs e)
        {
            //get the current time
            int hh = DateTime.Now.Hour;
            int mm = DateTime.Now.Minute;
            int ss = DateTime.Now.Second;


            //Time
            string time = "";

            //padding leading zero
            if (hh < 10)
            {
                time += "0" + hh;
            }

            else
            {
                time += hh;

            }
            time += ":";

            if (mm < 10)
            {
                time += "0" + mm;
            }
            else
            {
                time += mm;

            }
            time += ":";

            if (ss < 10)
            {
                time += "0" + ss;

            }
            else
            {
                time += ss;
            }
            //update label

            timeLabel.Text = time;
        }
 
        


        private void closeLabel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void topPanel_Paint(object sender, PaintEventArgs e)
        {

        }


        private void dashPanel_MouseEnter_1(object sender, EventArgs e)
        {
            dashPanel.BackColor = System.Drawing.ColorTranslator.FromHtml("#1E1E1E");
        }

        private void dashPanel_MouseLeave(object sender, EventArgs e)
        {
            dashPanel.BackColor = Color.Transparent;
        }

        private void sideDashboard_MouseEnter(object sender, EventArgs e)
        {
            dashPanel.BackColor = System.Drawing.ColorTranslator.FromHtml("#1E1E1E");
        }

        private void mostActive_MouseEnter(object sender, EventArgs e)
        {
            dashActive.BackColor = System.Drawing.ColorTranslator.FromHtml("#1E1E1E");
        }

        private void mostActive_MouseLeave(object sender, EventArgs e)
        {
            dashActive.BackColor = Color.Transparent;
        }

        private void mostGainers_MouseEnter(object sender, EventArgs e)
        {
            dashGain.BackColor = System.Drawing.ColorTranslator.FromHtml("#1E1E1E");
        }

        private void mostGainers_MouseLeave(object sender, EventArgs e)
        {
            dashGain.BackColor = Color.Transparent;
        }

        private void mostLosers_MouseEnter(object sender, EventArgs e)
        {
            dashLose.BackColor = System.Drawing.ColorTranslator.FromHtml("#1E1E1E");
        }

        private void mostLosers_MouseLeave(object sender, EventArgs e)
        {
            dashLose.BackColor = Color.Transparent;
        }

        private void label2_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void label4_MouseEnter(object sender, EventArgs e)
        {
            stocksPan.BackColor = System.Drawing.ColorTranslator.FromHtml("#9c9c9c");
        }

        private void label4_MouseLeave(object sender, EventArgs e)
        {
            stocksPan.BackColor = Color.Transparent;
        }

        private void label4_Click(object sender, EventArgs e)
        {
            var driver = new FirefoxDriver();
            driver.Navigate().GoToUrl("https://www.tradingview.com/");
        }

        private void label6_MouseEnter(object sender, EventArgs e)
        {
            stocksPanChrome.BackColor = System.Drawing.ColorTranslator.FromHtml("#9c9c9c");
        }

        private void label6_MouseLeave(object sender, EventArgs e)
        {
            stocksPanChrome.BackColor = Color.Transparent;
        }

        private void label6_Click(object sender, EventArgs e)
        {
            //var chromeDriver = new ChromeDriver();
            //chromeDriver.Navigate().GoToUrl("https://www.tradingview.com/");
        }

        private void stockList_TextChanged(object sender, EventArgs e)
        {
        }


        private void sideDashboard_Click(object sender, EventArgs e)
        {
            activePan.Visible = false;
            gainpan.Visible = false;
            losPan.Visible = false;
        }

        private void mostActive_Click(object sender, EventArgs e)
        {
            activePan.Visible = true;
            gainpan.Visible = false;

        }

        private void mostGainers_Click(object sender, EventArgs e)
        {
            activePan.Visible = true;
            gainpan.Visible = true;
            losPan.Visible = false;
        }

        private void mostLosers_Click(object sender, EventArgs e)
        {
            activePan.Visible = true;
            gainpan.Visible = true;
            losPan.Visible = true;
        }

        private void label11_Click(object sender, EventArgs e)
        {
            var getTopFive = new FirefoxDriver();
            getTopFive.Navigate().GoToUrl("https://www.tradingview.com/");

//This used to be the first one
            IList<IWebElement> movies = getTopFive.FindElements(By.CssSelector("[data-symbol='NASDAQ:SIRI']")); 


            for (int i = 0; i < 1; ++i)
            {
                activeTextBox.Text = movies[i].Text;
                
            }

        }

        private void activePan_Paint(object sender, PaintEventArgs e)
        {
            Label scan = new Label();
            scan.Text = "Test";
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            var homePage = new FirefoxDriver();
            homePage.Navigate().GoToUrl("http://www.vargadevelopments.com");
        }

        private void label1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        }
    }


@SAKyrukov
SAKryukov

What I have tried:

I've tried changing the CssSelector but it either gave me an error or didnt do anything at all, I think im using them the wrong way.
Posted
Updated 27-May-16 9:33am
v2
Comments
Sergey Alexandrovich Kryukov 15-Apr-16 9:00am    
You are lost. The scraping you described seems easy, but I have no idea how to help you, because you seemingly ignore any help or don't understand it. How about your previous question and bug? Did you understand the solution? Fixed the code? Accepted the solution?

And now more news, the timer. And selector. How to deal with that?

—SA
BladeLogan 15-Apr-16 10:24am    
Here is where I think you are wrong, no disrespect, its just that the last question I had, it got answered, which made me progress to the state the software is in right now, There is nothing wrong with the software, its fully functional its pulling data etc, but its not pulling it correctly, Not sure what you mean about the timer, the timer I added is just a clock that I have on the software, it has nothing what so ever to do with the scraping part, the scraping starts under

private void label11_Click(object sender, EventArgs e)

a bit down the code, Im not ignoring the help, I got help with the last bug, its just that it fixed it but not in the way I really wanted it in, which probably doesnt make any sense what so ever but I can assure you that the last question is very different from this one.
BladeLogan 15-Apr-16 10:34am    
Also, the last question was more about teaching me how to actually pull data which I didnt know before. Now I need to know how to pull data correctly.
BladeLogan 15-Apr-16 23:11pm    
Okay, I found the solution for the "real time updater", instead of pulling thw wrong CssSelector I started pulling
FindElements(By.CssSelector("tbody tr"));
Now its pulling whats on top of the table at all times

before I just pulled what was currently on top with
getTopFive.FindElements(By.CssSelector("[data-symbol='NASDAQ:SIRI']"));

Dont get me wrong I still dont understand the CssSelector, and I couldnt find any documents about it, what im going to do now is read more about elements.

1 solution

When trying to use selenium it is important to get a grasp on Xpath. If instead of using the css selector you search by xpath you can try something like this:
//div[@id='market-summary-body']/div[2]/div[@class='pages']/div/div/table/tbody/tr
Which I tested in google chrome will get you a list of all the top active rows.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900