我想将文本框文本转换为字符串变量并将其发送到另一个类并在 sendkey 中使用它
public void ScreenshotOfElement()
{
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("https://allcoins.pw/");
driver.FindElement(By.XPath("//input[@id='captchal']")).SendKeys(str);
}
private void Button1_Click(object sender, EventArgs e)
{
string str = textBox1.Text;
}
最佳答案
您的函数中的一些变化如下:
public string Button1_Click(object sender, EventArgs e)
{
string str = textBox1.Text;
return str;
}
假设您已经将字符串作为 Text 函数返回字符串本身。如果它没有打印您的 str
值,如果您没有得到结果,则说明您的定位器有问题。
您需要将函数从private 更改为public,因为您需要在另一个类中输出此输出,如果函数保持私有(private),则您无法在类外调用它。
您还需要将函数的返回参数从 void 更改为 String。否则无论你在哪里调用函数,它都不会返回任何东西。
在您获得文本或所需结果的函数中添加关键字 return。
现在您只需要创建一个类的对象并调用该函数,因为它是非静态的。
你可以像下面那样做:
假设你的类名是obj
Obj obj= new Obj();
obj.Button1_Click(PARA1,PARA2)
关于c# - 如何将文本框文本更改为字符串变量并将其发送到另一个类并在 sendkey 中使用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57158535/