Clicking a Link on a Web page by using Keywords - c#

I want to be able to open supreme's website, (www.supremenewyork.com), go to any of the tabs (shirts, jackets, etc.) and be able to input the keywords of the shirt I want to click on, and then have my program click on it.
I figured out how to get it to automatically click onto checkout and fill out the fields. Here is the html for a random shirt that we will use for example.
https://www.supremenewyork.com/shop/all/shirts
I want to click on the Houndstooth Flannel Zip Up Shirt in the color Red
I have read that you need to use HTMLAgilityPack to be able to type in those inner text's for the keywords. But I think you guys can send me the right way.
Here is the HTML
<article><div class="inner-article"><a style="height:150px;" href="/shop/shirts/gsfge9btl/mkza7miyc"><img width="150" height="150" src="//assets.supremenewyork.com/160974/vi/eYFAEBVxJT0.jpg" alt="Eyfaebvxjt0"></a><h1><a class="name-link" href="/shop/shirts/gsfge9btl/mkza7miyc">Houndstooth Flannel Zip Up Shirt</a></h1><p><a class="name-link" href="/shop/shirts/gsfge9btl/mkza7miyc">Red</a></p></div></article>
Here is my code
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 HtmlAgilityPack;
namespace Supreme
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Navigate("https://supremenewyork.com/shop");
}
private void button1_Click(object sender, EventArgs e)
{
webBrowser1.Navigate("https://www.supremenewyork.com/shop/accessories");
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
foreach (HtmlElement btn in
webBrowser1.Document.GetElementsByTagName("input"))
{
if (btn.GetAttribute("className") == "button")
{
btn.InvokeMember("Click");
}
}
}
private void button2_Click(object sender, EventArgs e)
{
webBrowser1.Navigate("https://supremenewyork.com/shop/all/shirts");
}
private void button3_Click(object sender, EventArgs e)
{
webBrowser1.GoBack();
}
private void button4_Click(object sender, EventArgs e)
{
foreach (HtmlElement btn in
webBrowser1.Document.GetElementsByTagName("a"))
{
if (btn.GetAttribute("className") == "button checkout")
{
btn.InvokeMember("Click");
}
}
}
}
THANK YOU!

Related

C# How to update IE7 to new version

Iam very new to coding so please pardon my lack of knowledge.
I made a program "Music player" that uses webBrowser to play video from youtube but from what i understood from other posts it cant work due to webBrowser being IE7. I dont neccessarily have to use webBrowser but it seemed like the best way.
Is there a way to "update" IE or do i need to use different method?
code:
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 System.Text.RegularExpressions;
namespace MusicPlayer_V4._1
{
public partial class Form1 : Form
{
string _ytUrl;
public Form1()
{
InitializeComponent();
}
public string VideoId
{
get
{
var ytMatch = new Regex(#"youtu(?:\.be|be\.com) / (?:.*v(?:.*/|=)|(?:.*/)?)([a-zA-Z0-_]+)").Match(_ytUrl);
return ytMatch.Success ? ytMatch.Groups[1].Value : string.Empty;
}
}
//user input (URL)
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
//play button
private void button1_Click(object sender, EventArgs e)
{
_ytUrl = txtUrl.Text;
webBrowser.Navigate($"http://youtube.com/v/{VideoId}?version=3");
}
//help button
private void button2_Click(object sender, EventArgs e)
{
}
//browser
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}
The way moving forward is to use WebView2 which is basically the same thing as a WebView but based on the chromium-based edge. It will be always up to date on windows 10/11 machines and it works down to Windows 7.
https://developer.microsoft.com/en-us/microsoft-edge/webview2/

How to make a link in RichTextBox clickable

I am currently using WinForms Application and it seems that I have ran into a problem. I have a button that when pressed it outputs a link in a RichTextBox. However, the link is highlighted in blue but when I click it does not open in my browser. Here is the code(Note that https://something.com/ represents an actual link.):
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Project
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
richTextBox1.Text = "https://something.com/" + textBox1.Text;
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
}
}

By pressing a button i want to show the user all the data inserted to the boxes

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;
namespace Apostolh_Texnikou
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void label4_Click(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
private void GN_TextChanged(object sender, EventArgs e)
{
}
private void CP_TextChanged(object sender, EventArgs e)
{
}
private void textBox5_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}
I want the user to click in the ready button and a window to pop out.
In the window the user must be able to copy the text.
I found how to make a pop window but its just a window which doesn't allow
copy paste. thank you in advance
You might want to look into a more complex type of dialog box. Perhaps one with a textbox? This will require launching another form. (see how to display textBox control in MessageBox?)

saving information in a database/displaying them in a GUI window. (Visual Studios)

I am trying to make a room request program and have two windows that I need to connect to the database (which I know how to do). The two windows are called EMERGENCY and JANITOR. My issue is I don't know how to store information in a database. Like let's say someone logs in as EMERGENCY and sends a request, the information needs to be stored and once the JANITOR logs in, he can see the requests. So far I have the database but not sure about storing information in it without manually adding them. If anyone has any guides or links on how to do this, I'd appreciate it!
EMERGENCY window code:
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 System.Data.SqlClient;
namespace LOGINPAGE
{
public partial class EMERGENCY : Form
{
public EMERGENCY()
{
InitializeComponent();
}
void Fillcombo()
{
}
private void EMERGENCY_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'roomInfoDataSet6.Table' table. You can move, or remove it, as needed.
}
private void xButton1_Click(object sender, EventArgs e)
{
this.Close();
Application.Exit();
}
private void xButton2_Click(object sender, EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void Search_Click(object sender, EventArgs e)
{
}
}
}
JANITOR code:
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;
namespace LOGINPAGE
{
public partial class JANITOR : Form
{
public JANITOR()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void JANITOR_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'roomInfoDataSet3.Table' table. You can move, or remove it, as needed.
this.tableTableAdapter.Fill(this.roomInfoDataSet3.Table);
}
private void xButton4_Click(object sender, EventArgs e)
{
}
private void xButton2_Click(object sender, EventArgs e)
{
this.Close();
Application.Exit();
}
}
}
EMERGENCY
JANITOR
You can use Ms access db
You will find connecting to acess from c# to really easy with lots of YouTube video tutorials
I can have a table in it database that is updated by a "save emergency" button and a load emergency button by the janitor will just populate a datagridview with items from the same table filled with the first button

C# Windows Forms - Textbox in Form2 into List item Form1 [duplicate]

This question already has answers here:
Send values from one form to another form
(20 answers)
Closed 7 years ago.
I am having a problem adding text from my Form 2, to the List item in Form 1. Could anyone help please, Sorry if it's a bit jumbled, I'm new with coding :) What I am trying to achieve is a to-do list application, in the 2nd form, text should be entered in a text box - when the user clicks enter, this text should be entered into the list item.
Another question is, in this case would I be better using a list item or a list box?
Here is the code:
FORM 2
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;
namespace ToDoList
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public void button2_Click(object sender, EventArgs e, string tbtext)
{
//Form1 form1 = new Form1();
//form1.listBox1.Items.Add(tbtext);
}
public void button1_Click(object sender, EventArgs e)
{
this.Close();
}
public void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
ListViewItem item = new ListViewItem(textBox1.Text);
Form1 f1 = new Form1();
f1.listView1.Items.Add(item);
}
private void textBox1_TextChanged_1(object sender, EventArgs e)
{
}
}
}
FORM 1
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;
namespace ToDoList
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void filesToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.Show();
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
public void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
public void button2_Click(object sender, EventArgs e)
{
}
public void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void F1Button1_Click(object sender, EventArgs e)
{
}
private void tB1_TextChanged(object sender, EventArgs e)
{
}
public void listView1_SelectedIndexChanged_1(object sender, EventArgs e)
{
}
}
}
You create different object Form1, and the object is destroyd after you quit button2_Click. Is it local variable.
You need to create the datasource for your TODO list and propaget it to both forms, for example by method Set DataSource. Then you have one object accesible by
both forms.

Categories