diff --git a/SereinWAT/SereinWAT.cs b/SereinWAT/SereinWAT.cs index f005f76..3ab76f3 100644 --- a/SereinWAT/SereinWAT.cs +++ b/SereinWAT/SereinWAT.cs @@ -4,6 +4,7 @@ using OpenQA.Selenium.Edge; using OpenQA.Selenium.Firefox; using OpenQA.Selenium.IE; using Serein.NodeFlow; +using static System.Net.Mime.MediaTypeNames; namespace Serein.Module { @@ -69,14 +70,11 @@ namespace Serein.Module public void Wait([Explicit]int time = 1000) { Thread.Sleep(time); - } [MethodDetail(DynamicNodeType.Action,"启动浏览器")] public WebDriver OpenDriver([Explicit] bool isVisible = true,[Explicit] DriverType driverType = DriverType.Chrome) { - - if(driverType == DriverType.Chrome) { ChromeOptions options = new ChromeOptions(); @@ -145,6 +143,34 @@ namespace Serein.Module [MethodDetail(DynamicNodeType.Action,"定位元素")] public IWebElement FindElement([Explicit] string key = "", [Explicit] ByType byType = ByType.XPath, [Explicit] int index = 0) { + By by = byType switch + { + ByType.Id => By.Id(key), + ByType.XPath => By.XPath(key), + ByType.Class => By.ClassName(key), + ByType.Name => By.Name(key), + ByType.CssSelector => By.CssSelector(key), + ByType.PartialLinkText => By.PartialLinkText(key), + }; + if(index == -1) + { + return WebDriver.FindElements(by).First(); + } + else + { + return WebDriver.FindElements(by)[index]; + } + } + + [MethodDetail(DynamicNodeType.Action, "定位并操作元素")] + public IWebElement FindAndUseElement([Explicit] ByType byType = ByType.XPath, + [Explicit] string key = "", + [Explicit] ActionType actionType = ActionType.Click, + [Explicit] string text = "", + [Explicit] int index = 0, + [Explicit] int waitTime = 0) + { + Thread.Sleep(waitTime); By by = byType switch { ByType.Id => By.Id(key), @@ -155,8 +181,29 @@ namespace Serein.Module ByType.PartialLinkText => By.PartialLinkText(key), }; var element = WebDriver.FindElements(by)[index]; + Thread.Sleep(waitTime); + var actions = new OpenQA.Selenium.Interactions.Actions(WebDriver); + switch (actionType) + { + case ActionType.Click: + actions.Click(element).Perform(); + break; + case ActionType.DoubleClick: + actions.DoubleClick(element).Perform(); + break; + case ActionType.RightClick: + actions.ContextClick(element).Perform(); + break; + case ActionType.SendKeys: + element.Click(); + element.Clear(); + element.SendKeys(text); + break; + } + return element; } + [MethodDetail(DynamicNodeType.Action, "操作元素")] public void PerformAction(IWebElement element, [Explicit] ActionType actionType = ActionType.Click, [Explicit] string text = "") { @@ -191,6 +238,10 @@ namespace Serein.Module } else if (scriptOp == ScriptOp.Modify) { + element.SetAttribute(WebDriver, attributeName, value); + string newHref = element.GetAttribute("href"); + Console.WriteLine("New href value: " + newHref); + WebDriver.ExecuteScript("arguments[0].setAttribute(arguments[1], arguments[2]);", element, attributeName, value); } else if (scriptOp == ScriptOp.Delete) @@ -206,4 +257,13 @@ namespace Serein.Module return element.GetAttribute(attributeName); } } + + public static class MyExtension + { + public static void SetAttribute(this IWebElement element, IWebDriver driver, string attributeName, string value) + { + IJavaScriptExecutor js = (IJavaScriptExecutor)driver; + js.ExecuteScript($"arguments[0].setAttribute('{attributeName}', '{value}');", element); + } + } } diff --git a/WorkBench/App.xaml.cs b/WorkBench/App.xaml.cs index 3a9107d..952e1c6 100644 --- a/WorkBench/App.xaml.cs +++ b/WorkBench/App.xaml.cs @@ -34,7 +34,6 @@ namespace Serein.WorkBench { #if false //测试 操作表达式,条件表达式 - #region 测试数据 string expression = ""; @@ -151,13 +150,14 @@ namespace Serein.WorkBench Shutdown(); // 关闭应用程序 } } - //else if (1 == 1) - //{ - // string filePath = @"F:\临时\project\wat project.dnf"; - // string content = System.IO.File.ReadAllText(filePath); // 读取整个文件内容 - // FData = JsonConvert.DeserializeObject(content); - // App.FileDataPath = System.IO.Path.GetDirectoryName(filePath); - //} + else if (1 == 1) + { + string filePath = @"F:\临时\project\U9 project.dnf"; + //string filePath = @"D:\Project\C#\DynamicControl\SereinFlow\.Output\Debug\net8.0-windows7.0\U9 project.dnf"; + string content = System.IO.File.ReadAllText(filePath); // 读取整个文件内容 + FData = JsonConvert.DeserializeObject(content); + App.FileDataPath = System.IO.Path.GetDirectoryName(filePath); + } } } diff --git a/WorkBench/MainWindow.xaml.cs b/WorkBench/MainWindow.xaml.cs index d828b09..22282c6 100644 --- a/WorkBench/MainWindow.xaml.cs +++ b/WorkBench/MainWindow.xaml.cs @@ -397,7 +397,7 @@ namespace Serein.WorkBench } var connection = new Connection { Start = fromNode, End = toNode, Type = connectionType }; toNode.Node.PreviousNodes.Add(fromNode.Node); - DraggableControl.CreateLinx(FlowChartCanvas, connection); + BsControl.Draw(FlowChartCanvas, connection); ConfigureLineContextMenu(connection); connections.Add(connection); } @@ -1362,7 +1362,7 @@ namespace Serein.WorkBench } // 保存连接关系 - DraggableControl.CreateLinx(FlowChartCanvas, connection); + BsControl.Draw(FlowChartCanvas, connection); ConfigureLineContextMenu(connection); targetBlock.Node.PreviousNodes.Add(startConnectBlock.Node); // 将当前发起连接的节点,添加到被连接的节点的上一节点队列。(用于回溯) @@ -2004,9 +2004,9 @@ namespace Serein.WorkBench #region 创建两个控件之间的连接关系,在UI层面上显示为 带箭头指向的贝塞尔曲线 - public static class DraggableControl + public static class BsControl { - public static Connection CreateLinx(Canvas canvas, Connection connection) + public static Connection Draw(Canvas canvas, Connection connection) { UpdateBezierLine(canvas, connection); //MakeDraggable(canvas, connection, connection.Start); @@ -2101,7 +2101,6 @@ namespace Serein.WorkBench //} - } diff --git a/WorkBench/Node/View/ActionNodeControl.xaml b/WorkBench/Node/View/ActionNodeControl.xaml index 4cc9b6f..13ca862 100644 --- a/WorkBench/Node/View/ActionNodeControl.xaml +++ b/WorkBench/Node/View/ActionNodeControl.xaml @@ -6,7 +6,7 @@ xmlns:local="clr-namespace:Serein.WorkBench.Node.View" xmlns:vm="clr-namespace:Serein.WorkBench.Node.ViewModel" xmlns:themes="clr-namespace:Serein.WorkBench.Themes" - > + MaxWidth="300"> @@ -17,10 +17,18 @@ - - - + + + + + + + + + + + diff --git a/WorkBench/Node/View/ActionRegionControl.xaml b/WorkBench/Node/View/ActionRegionControl.xaml index a9d8636..6e2021b 100644 --- a/WorkBench/Node/View/ActionRegionControl.xaml +++ b/WorkBench/Node/View/ActionRegionControl.xaml @@ -3,7 +3,8 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:local="clr-namespace:Serein.WorkBench.Node.View"> + xmlns:local="clr-namespace:Serein.WorkBench.Node.View" + MaxWidth="300"> diff --git a/WorkBench/Node/View/ConditionNodeControl.xaml b/WorkBench/Node/View/ConditionNodeControl.xaml index 4b737ab..2b09c93 100644 --- a/WorkBench/Node/View/ConditionNodeControl.xaml +++ b/WorkBench/Node/View/ConditionNodeControl.xaml @@ -5,7 +5,8 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Serein.WorkBench.Node.View" xmlns:vm="clr-namespace:Serein.WorkBench.Node.ViewModel" - xmlns:themes="clr-namespace:Serein.WorkBench.Themes"> + xmlns:themes="clr-namespace:Serein.WorkBench.Themes" + MaxWidth="300"> diff --git a/WorkBench/Node/View/ConditionRegionControl.xaml b/WorkBench/Node/View/ConditionRegionControl.xaml index 6b62ae2..5d13f71 100644 --- a/WorkBench/Node/View/ConditionRegionControl.xaml +++ b/WorkBench/Node/View/ConditionRegionControl.xaml @@ -3,7 +3,8 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:local="clr-namespace:Serein.WorkBench.Node.View"> + xmlns:local="clr-namespace:Serein.WorkBench.Node.View" + MaxWidth="300"> diff --git a/WorkBench/Node/View/DllControlControl.xaml b/WorkBench/Node/View/DllControlControl.xaml index 2d311c5..77403bb 100644 --- a/WorkBench/Node/View/DllControlControl.xaml +++ b/WorkBench/Node/View/DllControlControl.xaml @@ -4,6 +4,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Serein.WorkBench.Node.View" + MaxWidth="300" > diff --git a/WorkBench/Node/View/ExpOpNodeControl.xaml b/WorkBench/Node/View/ExpOpNodeControl.xaml index f84b1e8..832a28f 100644 --- a/WorkBench/Node/View/ExpOpNodeControl.xaml +++ b/WorkBench/Node/View/ExpOpNodeControl.xaml @@ -3,7 +3,8 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:local="clr-namespace:Serein.WorkBench.Node.View"> + xmlns:local="clr-namespace:Serein.WorkBench.Node.View" + MaxWidth="300"> diff --git a/WorkBench/Node/View/FlipflopNodeControl.xaml b/WorkBench/Node/View/FlipflopNodeControl.xaml index 39ecf29..c400edb 100644 --- a/WorkBench/Node/View/FlipflopNodeControl.xaml +++ b/WorkBench/Node/View/FlipflopNodeControl.xaml @@ -5,7 +5,8 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Serein.WorkBench.Node.View" xmlns:vm="clr-namespace:Serein.WorkBench.Node.ViewModel" - xmlns:themes="clr-namespace:Serein.WorkBench.Themes"> + xmlns:themes="clr-namespace:Serein.WorkBench.Themes" + MaxWidth="300"> diff --git a/WorkBench/Themes/MethodDetailsControl.xaml b/WorkBench/Themes/MethodDetailsControl.xaml index 64dd2ab..e5665ca 100644 --- a/WorkBench/Themes/MethodDetailsControl.xaml +++ b/WorkBench/Themes/MethodDetailsControl.xaml @@ -35,7 +35,7 @@ - + @@ -60,7 +60,7 @@ - + - +