我使用的是Windows Form;
我想设置我的表单上的TextBox tbCommandName1.Text
;
我从GetInfo()
得到了价值,如何将Second.GetInfo()
的字符串发送到我的主表单,就像上课Favorit
一样?
我不想创建Form
的实例;因为它再次初始化我的所有组件。
我打赌我必须使用get / set。
请给我一些提示;
谢谢,我的大师!
namespace ParserFavorit
{
public partial class Favorit : Form, IForm
{
public Favorit()
{
InitializeComponent();
}
public string CommandName1
{
get { return tbCommandName1.Text; }
set { tbCommandName1.Text = value; }
}
private void bStart_Click(object sender, EventArgs e)
{
string ID = tbGetID.Text;
Second.StartBrowser(Second.GetDriver(), ID);
}
}
public class Second : Form
{
private static ChromeDriver driver = null;
public static ChromeDriver GetDriver()
{
if (driver == null)
{
driver = new ChromeDriver();
}
return driver;
}
public static void StartBrowser(ChromeDriver driver, string IDevent)
{
driver.Navigate().GoToUrl("myURL" + IDevent);
GetInfo();
}
public static void GetInfo()
{
System.Threading.Thread.Sleep(2000);
string CommandName1 = driver.FindElement(By.XPath(".//*[@id='react-root']/div/div[2]/div/div[1]/div/div[1]/div/div[1]/div/header/div[2]/span[1]")).Text;
string CommandName2 = driver.FindElement(By.XPath(".//*[@id='react-root']/div/div[2]/div/div[1]/div/div[1]/div/div[1]/div/header/div[2]/span[2]")).GetAttribute("innerHTML");
}
}
interface IForm
{
string CommandName1 { get; set; }
}
}
答案 0 :(得分:0)
我确信我有一个名为tbCommandName1的TextBox;
我的表单没有显示我从网站获得的价值,但方法PrintName
得到了它。
怎么会这样?
命名空间ParserFavorit { public partial class收藏:表格 { public Favorit() { 的InitializeComponent(); }
private void bStart_Click(object sender, EventArgs e)
{
string ID = tbGetID.Text;
Second.StartBrowser(Second.GetDriver(), ID);
}
public void PrintName(string Command1Name)
{
string Name = Command1Name;
tbCommandName1.Text = Name;
}
}
public class Second
{
private static ChromeDriver driver = null;
public static ChromeDriver GetDriver()
{
if (driver == null)
{
driver = new ChromeDriver();
}
return driver;
}
public static void StartBrowser(ChromeDriver driver, string ID)
{
driver.Navigate().GoToUrl("https://m.favorit.com.ua/uk/live/events/" + ID);
GetInfo();
}
public static void GetInfo()
{
System.Threading.Thread.Sleep(2000);
string CommandName1 = driver.FindElement(By.XPath(".//*[@id='react-root']/div/div[2]/div/div[1]/div/div[1]/div/div[1]/div/header/div[2]/span[1]")).Text;
Favorit favorit = new Favorit();
favorit.PrintName(CommandName1);
}
}
}