@@ -94,6 +94,7 @@ internal static async Task WriteCoordinates(Account acc, Coordinates coordinates
94
94
await WriteById ( acc , "yCoordInput" , coordinates . y ) ;
95
95
}
96
96
97
+ #region By Id
97
98
public static async Task < bool > ClickById ( Account acc , string query , bool log = true ) =>
98
99
await ExecuteAction ( acc , new QueryById ( query ) , new ActionClick ( ) , log ) ;
99
100
@@ -105,6 +106,9 @@ public static async Task<bool> CheckById(Account acc, string query, bool check,
105
106
106
107
public static async Task < bool > SelectIndexById ( Account acc , string query , int index , bool log = true ) =>
107
108
await ExecuteAction ( acc , new QueryById ( query ) , new ActionSelectIndex ( index ) , log ) ;
109
+ #endregion
110
+
111
+ #region By Class Name
108
112
109
113
public static async Task < bool > ClickByClassName ( Account acc , string query , bool log = true ) =>
110
114
await ExecuteAction ( acc , new QueryByClassName ( query ) , new ActionClick ( ) , log ) ;
@@ -117,6 +121,9 @@ public static async Task<bool> CheckByClassName(Account acc, string query, bool
117
121
118
122
public static async Task < bool > SelectIndexByClassName ( Account acc , string query , int index , bool log = true ) =>
119
123
await ExecuteAction ( acc , new QueryByClassName ( query ) , new ActionSelectIndex ( index ) , log ) ;
124
+ #endregion
125
+
126
+ #region By Name
120
127
121
128
public static async Task < bool > ClickByName ( Account acc , string query , bool log = true ) =>
122
129
await ExecuteAction ( acc , new QueryByName ( query ) , new ActionClick ( ) , log ) ;
@@ -129,47 +136,56 @@ public static async Task<bool> CheckByName(Account acc, string query, bool check
129
136
130
137
public static async Task < bool > SelectIndexByName ( Account acc , string query , int index , bool log = true ) =>
131
138
await ExecuteAction ( acc , new QueryByName ( query ) , new ActionSelectIndex ( index ) , log ) ;
139
+ #endregion
140
+
141
+ #region By Attribute Value
142
+ public static async Task < bool > ClickByAttributeValue ( Account acc , string attribute , string value , bool log = true ) =>
143
+ await ExecuteAction ( acc , new QueryByAttributeVal ( attribute , value ) , new ActionClick ( ) , log ) ;
144
+
145
+ public static async Task < bool > WriteByAttributeValue ( Account acc , string attribute , string value , object text , bool log = true , bool update = true ) =>
146
+ await ExecuteAction ( acc , new QueryByAttributeVal ( attribute , value ) , new ActionWrite ( text ) , log , update ) ;
147
+
148
+ public static async Task < bool > CheckByAttributeValue ( Account acc , string attribute , string value , bool check , bool log = true ) =>
149
+ await ExecuteAction ( acc , new QueryByAttributeVal ( attribute , value ) , new ActionCheck ( check ) , log ) ;
150
+
151
+ public static async Task < bool > SelectByAttributeValue ( Account acc , string attribute , string value , int index , bool log = true ) =>
152
+ await ExecuteAction ( acc , new QueryByAttributeVal ( attribute , value ) , new ActionSelectIndex ( index ) , log ) ;
153
+ #endregion
132
154
133
155
private static async Task < bool > ExecuteAction ( Account acc , Query query , Action action , bool log = true , bool update = true ) =>
134
156
await ExecuteScript ( acc , $ "document.{ query . val } { action . val } ", log , update ) ;
135
157
136
158
public class QueryById : Query
137
-
138
159
{ public QueryById ( string str ) => base . val = $ "getElementById('{ str } ')"; }
139
160
140
161
public class QueryByName : Query
141
-
142
162
{ public QueryByName ( string str ) => base . val = $ "getElementsByName('{ str } ')[0]"; }
143
163
144
164
public class QueryByClassName : Query
145
-
146
165
{ public QueryByClassName ( string str ) => base . val = $ "getElementsByClassName('{ str } ')[0]"; }
147
166
148
- public class ActionWrite : Action
167
+ public class QueryByAttributeVal : Query
168
+ { public QueryByAttributeVal ( string attribute , string value ) => base . val = $ "querySelectorAll('[{ attribute } =\" { value } \" ]')[0]"; }
149
169
170
+
171
+ public class ActionWrite : Action
150
172
{ public ActionWrite ( object str ) => base . val = $ ".value='{ str } ';"; }
151
173
152
174
public class ActionClick : Action
153
-
154
175
{ public ActionClick ( ) => base . val = ".click();" ; }
155
-
156
176
public class ActionCheck : Action
157
-
158
177
{ public ActionCheck ( bool check ) => base . val = $ ".checked={ ( check ? "true" : "false" ) } ;"; }
159
178
160
179
public class ActionSelectIndex : Action
161
-
162
180
{ public ActionSelectIndex ( int index ) => base . val = $ ".selectedIndex = { index } ;"; }
163
181
164
- public abstract class Action
165
- { public string val ; }
182
+ public abstract class Action { public string val ; }
166
183
167
- public abstract class Query
168
- { public string val ; }
184
+ public abstract class Query { public string val ; }
169
185
170
- public static async Task WaitLoaded ( Account acc , int delay = 10 )
186
+ public static async Task WaitLoaded ( Account acc , int delay = 15 )
171
187
{
172
- var wait = new WebDriverWait ( acc . Wb . Driver , TimeSpan . FromMinutes ( delay ) ) ;
188
+ var wait = new WebDriverWait ( acc . Wb . Driver , TimeSpan . FromSeconds ( delay ) ) ;
173
189
wait . Until ( driver => ( ( IJavaScriptExecutor ) driver ) . ExecuteScript ( "return document.readyState" ) . Equals ( "complete" ) ) ;
174
190
acc . Wb . UpdateHtml ( ) ;
175
191
await TaskExecutor . PageLoaded ( acc ) ;
0 commit comments