问题: 我正在使用 Selenium - C# 编写一些功能测试。 我必须在代码镜像文本区域中添加两行 CSS。似乎我只能通过使用 class = CodeMirror 定位主“div”来在我的 C# 代码中使用 Javascript 来完成它。即 shown in this image
但是当我使用这段代码时:
IJavaScriptExecutor js = (IJavaScriptExecutor) Driver;
string ExistingCSS=null;
for (int i = 0; i < table.RowCount; i++)
{
ScrollIntoView(Driver.FindElement(By.ClassName("CodeMirror")));
ExistingCSS = ExistingCSS + Driver.FindElement(By.ClassName("CodeMirror")).FindElements(By.ClassName("CodeMirror-line"))[i].Text;
Console.WriteLine(" Existing CSS -> "+ ExistingCSS);
js.ExecuteScript("arguments[0].CodeMirror.setValue(\"" + ExistingCSS + table.Rows[i]["CssValue"] + "\")", Driver.FindElement(By.ClassName("CodeMirror")));
};
它添加了这些行,但下次当我运行相同的代码时,它会覆盖该代码镜像文本区域中编写的内容。
帮助? 谢谢。 :)
最佳答案
ExistingCSS = ExistingCSS + Driver.FindElement(By.ClassName("CodeMirror")).FindElements(By.ClassName("CodeMirror-line"))[i].Text;
如下更改上面的行:
ExistingCSS += ExistingCSS + Driver.FindElement(By.ClassName("CodeMirror")).FindElements(By.ClassName("CodeMirror-line"))[i].Text;
关于javascript - 如何使用 JavaScript 将另一行添加到现有行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44497152/