Performing keyboard strokes “Ctrl + A” “Ctrl + C” and “Ctrl + V” on text field with selenium C#

北战南征 提交于 2019-12-07 12:22:47

问题


How to simply want to input a value in a text box , select the complete text from the text box using "Ctrl+a" , then copy it using "Ctrl + c" and then Paste it in the same box with "Ctrl + v" using Selenium + C#.


回答1:


[FindsBy(How = How.Id, Using = "search-criteria")]
public IWebElement txtProductSearch1 = null

public void copypaste(string strCopy)
{ 
    txtProductSearch1.Click();
    txtProductSearch1.Clear();
    txtProductSearch1.SendKeys(strCopy);
    txtProductSearch1.SendKeys(Keys.Control + "a"); //a in smaller case
    txtProductSearch1.SendKeys(Keys.Control + "c"); // c in smaller case
    txtProductSearch1.Clear();
    txtProductSearch1.SendKeys(Keys.Control + "v"); // v in smaller case
    btnProductSearch1.Click();
}


来源:https://stackoverflow.com/questions/26906197/performing-keyboard-strokes-ctrl-a-ctrl-c-and-ctrl-v-on-text-field-w

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!