c# selenium chrome webdriver shift + enter richtexbox



我使用的是c#硒铬网络驱动程序。我在Whatsapp web中名为div的_1Plpp类中使用SendKeys发送文本。但当RichTextBox中的新行结束时,WhatsApp会将其视为一条新文本。我想发一条短信。

String myText = richTextBox1.Text.Replace("n", OpenQA.Selenium.Keys.Shift + OpenQA.Selenium.Keys.Enter); 
driveri.FindElement(By.ClassName("_1Plpp")).SendKeys(richTextBox1.Text.Replace("rn", OpenQA.Selenium.Keys.Shift + OpenQA.Selenium.Keys.Enter));
driveri.FindElement(By.ClassName("_35EW6")).Click(); 

试试这个:

//Create an Actions object that will handle the keys.
Actions action = new Actions(driver);
//Tell the action object to send shift-enter and release them.
a.MoveToElement(driver.FindElement(By.ClassName("_1Plpp")))
.KeyDown(Keys.Shift)
.KeyDown(Keys.Enter)
.KeyUp(Keys.Enter)
.KeyUp(Keys.Shift);
//Do the action
a.Perform();
driver.FindElement(By.ClassName("_35EW6")).Click();

最新更新