How to use ElementHandleTapOptions class of Microsoft.Playwright package

Best Playwright-dotnet code snippet using Microsoft.Playwright.ElementHandleTapOptions

Run Playwright-dotnet automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

ElementHandleTapOptions.cs

Source: ElementHandleTapOptions.cs Github

copy
1/*
2 * MIT License
3 *
4 * Copyright (c) Microsoft Corporation.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25using System;
26using System.Collections.Generic;
27using System.ComponentModel.DataAnnotations;
28using System.Drawing;
29using System.Globalization;
30using System.IO;
31using System.Runtime.Serialization;
32using System.Text.Json;
33using System.Text.Json.Serialization;
34using System.Text.RegularExpressions;
35using System.Threading;
36using System.Threading.Tasks;
37
38#nullable enable
39
40namespace Microsoft.Playwright
41{
42    public class ElementHandleTapOptions
43    {
44        public ElementHandleTapOptions() { }
45
46        public ElementHandleTapOptions(ElementHandleTapOptions clone)
47        {
48            if (clone == null)
49            {
50                return;
51            }
52
53            Force = clone.Force;
54            Modifiers = clone.Modifiers;
55            NoWaitAfter = clone.NoWaitAfter;
56            Position = clone.Position;
57            Timeout = clone.Timeout;
58            Trial = clone.Trial;
59        }
60
61        /// <summary>
62        /// <para>
63        /// Whether to bypass the <a href="https://playwright.dev/dotnet/docs/actionability">actionability</a>
64        /// checks. Defaults to <c>false</c>.
65        /// </para>
66        /// </summary>
67        [JsonPropertyName("force")]
68        public bool? Force { get; set; }
69
70        /// <summary>
71        /// <para>
72        /// Modifier keys to press. Ensures that only these modifiers are pressed during the
73        /// operation, and then restores current modifiers back. If not specified, currently
74        /// pressed modifiers are used.
75        /// </para>
76        /// </summary>
77        [JsonPropertyName("modifiers")]
78        public IEnumerable<KeyboardModifier>? Modifiers { get; set; }
79
80        /// <summary>
81        /// <para>
82        /// Actions that initiate navigations are waiting for these navigations to happen and
83        /// for pages to start loading. You can opt out of waiting via setting this flag. You
84        /// would only need this option in the exceptional cases such as navigating to inaccessible
85        /// pages. Defaults to <c>false</c>.
86        /// </para>
87        /// </summary>
88        [JsonPropertyName("noWaitAfter")]
89        public bool? NoWaitAfter { get; set; }
90
91        /// <summary>
92        /// <para>
93        /// A point to use relative to the top-left corner of element padding box. If not specified,
94        /// uses some visible point of the element.
95        /// </para>
96        /// </summary>
97        [JsonPropertyName("position")]
98        public Position? Position { get; set; }
99
100        /// <summary>
101        /// <para>
102        /// Maximum time in milliseconds, defaults to 30 seconds, pass <c>0</c> to disable timeout.
103        /// The default value can be changed by using the <see cref="IBrowserContext.SetDefaultTimeout"/>
104        /// or <see cref="IPage.SetDefaultTimeout"/> methods.
105        /// </para>
106        /// </summary>
107        [JsonPropertyName("timeout")]
108        public float? Timeout { get; set; }
109
110        /// <summary>
111        /// <para>
112        /// When set, this method only performs the <a href="https://playwright.dev/dotnet/docs/actionability">actionability</a>
113        /// checks and skips the action. Defaults to <c>false</c>. Useful to wait until the
114        /// element is ready for the action without performing it.
115        /// </para>
116        /// </summary>
117        [JsonPropertyName("trial")]
118        public bool? Trial { get; set; }
119    }
120}
121
122#nullable disable
123
Full Screen

ElementHandle.cs

Source: ElementHandle.cs Github

copy
1/*
2 * MIT License
3 *
4 * Copyright (c) 2020 Darío Kondratiuk
5 * Modifications copyright (c) Microsoft Corporation.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25using System;
26using System.Collections.Generic;
27using System.IO;
28using System.Linq;
29using System.Text.Json;
30using System.Threading.Tasks;
31using Microsoft.Playwright.Helpers;
32using Microsoft.Playwright.Transport.Channels;
33using Microsoft.Playwright.Transport.Protocol;
34
35namespace Microsoft.Playwright.Core
36{
37    internal partial class ElementHandle : JSHandle, IElementHandle, IChannelOwner<ElementHandle>
38    {
39        private readonly ElementHandleChannel _channel;
40
41        internal ElementHandle(IChannelOwner parent, string guid, ElementHandleInitializer initializer) : base(parent, guid, initializer)
42        {
43            _channel = new(guid, parent.Connection, this);
44            _channel.PreviewUpdated += (_, e) => Preview = e.Preview;
45        }
46
47        ChannelBase IChannelOwner.Channel => _channel;
48
49        IChannel<ElementHandle> IChannelOwner<ElementHandle>.Channel => _channel;
50
51        internal IChannel<ElementHandle> ElementChannel => _channel;
52
53        public async Task<IElementHandle> WaitForSelectorAsync(string selector, ElementHandleWaitForSelectorOptions options = default)
54            => (await _channel.WaitForSelectorAsync(
55                selector: selector,
56                state: options?.State,
57                timeout: options?.Timeout,
58                strict: options?.Strict).ConfigureAwait(false))?.Object;
59
60        public Task WaitForElementStateAsync(ElementState state, ElementHandleWaitForElementStateOptions options = default)
61            => _channel.WaitForElementStateAsync(state, timeout: options?.Timeout);
62
63        public Task PressAsync(string key, ElementHandlePressOptions options = default)
64            => _channel.PressAsync(
65                key,
66                delay: options?.Delay,
67                timeout: options?.Timeout,
68                noWaitAfter: options?.NoWaitAfter);
69
70        public Task TypeAsync(string text, ElementHandleTypeOptions options = default)
71            => _channel.TypeAsync(text, delay: options?.Delay, timeout: options?.Timeout, noWaitAfter: options?.NoWaitAfter);
72
73        public async Task<byte[]> ScreenshotAsync(ElementHandleScreenshotOptions options = default)
74        {
75            options ??= new();
76            if (options.Type == null && !string.IsNullOrEmpty(options.Path))
77            {
78                options.Type = DetermineScreenshotType(options.Path);
79            }
80
81            byte[] result = await _channel.ScreenshotAsync(
82                options.Path,
83                options.OmitBackground,
84                options.Type,
85                options.Quality,
86                options.Mask,
87                options.Animations,
88                options.Caret,
89                options.Scale,
90                options.Timeout).ConfigureAwait(false);
91
92            if (!string.IsNullOrEmpty(options.Path))
93            {
94                Directory.CreateDirectory(new FileInfo(options.Path).Directory.FullName);
95                File.WriteAllBytes(options.Path, result);
96            }
97
98            return result;
99        }
100
101        public Task FillAsync(string value, ElementHandleFillOptions options = default)
102            => _channel.FillAsync(
103                value,
104                noWaitAfter: options?.NoWaitAfter,
105                force: options?.Force,
106                timeout: options?.Timeout);
107
108        public async Task<IFrame> ContentFrameAsync() => (await _channel.ContentFrameAsync().ConfigureAwait(false))?.Object;
109
110        public Task HoverAsync(ElementHandleHoverOptions options = default)
111            => _channel.HoverAsync(
112                modifiers: options?.Modifiers,
113                position: options?.Position,
114                timeout: options?.Timeout,
115                force: options?.Force,
116                trial: options?.Trial);
117
118        public Task ScrollIntoViewIfNeededAsync(ElementHandleScrollIntoViewIfNeededOptions options = default)
119            => _channel.ScrollIntoViewIfNeededAsync(options?.Timeout);
120
121        public async Task<IFrame> OwnerFrameAsync() => (await _channel.OwnerFrameAsync().ConfigureAwait(false)).Object;
122
123        public Task<ElementHandleBoundingBoxResult> BoundingBoxAsync() => _channel.BoundingBoxAsync();
124
125        public Task ClickAsync(ElementHandleClickOptions options = default)
126            => _channel.ClickAsync(
127                delay: options?.Delay,
128                button: options?.Button,
129                clickCount: options?.ClickCount,
130                modifiers: options?.Modifiers,
131                position: options?.Position,
132                timeout: options?.Timeout,
133                force: options?.Force,
134                noWaitAfter: options?.NoWaitAfter,
135                trial: options?.Trial);
136
137        public Task DblClickAsync(ElementHandleDblClickOptions options = default)
138            => _channel.DblClickAsync(
139                delay: options?.Delay,
140                button: options?.Button,
141                modifiers: options?.Modifiers,
142                position: options?.Position,
143                timeout: options?.Timeout,
144                force: options?.Force,
145                noWaitAfter: options?.NoWaitAfter,
146                trial: options?.Trial);
147
148        public Task SetInputFilesAsync(string files, ElementHandleSetInputFilesOptions options = default)
149            => SetInputFilesAsync(new[] { files }, options);
150
151        public async Task SetInputFilesAsync(IEnumerable<string> files, ElementHandleSetInputFilesOptions options = default)
152        {
153            var frame = await OwnerFrameAsync().ConfigureAwait(false);
154            if (frame == null)
155            {
156                throw new PlaywrightException("Cannot set input files to detached element.");
157            }
158            var converted = await SetInputFilesHelpers.ConvertInputFilesAsync(files, (BrowserContext)frame.Page.Context).ConfigureAwait(false);
159            if (converted.Files != null)
160            {
161                await _channel.SetInputFilesAsync(converted.Files, options?.NoWaitAfter, options?.Timeout).ConfigureAwait(false);
162            }
163            else
164            {
165                await _channel.SetInputFilePathsAsync(converted?.LocalPaths, converted?.Streams, options?.NoWaitAfter, options?.Timeout).ConfigureAwait(false);
166            }
167        }
168
169        public Task SetInputFilesAsync(FilePayload files, ElementHandleSetInputFilesOptions options = default)
170            => SetInputFilesAsync(new[] { files }, options);
171
172        public async Task SetInputFilesAsync(IEnumerable<FilePayload> files, ElementHandleSetInputFilesOptions options = default)
173        {
174            var converted = SetInputFilesHelpers.ConvertInputFiles(files);
175            await _channel.SetInputFilesAsync(converted.Files, options?.NoWaitAfter, options?.Timeout).ConfigureAwait(false);
176        }
177
178        public async Task<IElementHandle> QuerySelectorAsync(string selector)
179            => (await _channel.QuerySelectorAsync(selector).ConfigureAwait(false))?.Object;
180
181        public async Task<IReadOnlyList<IElementHandle>> QuerySelectorAllAsync(string selector)
182            => (await _channel.QuerySelectorAllAsync(selector).ConfigureAwait(false)).Select(e => ((ElementHandleChannel)e).Object).ToList().AsReadOnly();
183
184        public async Task<JsonElement?> EvalOnSelectorAsync(string selector, string expression, object arg = null)
185            => ScriptsHelper.ParseEvaluateResult<JsonElement?>(await _channel.EvalOnSelectorAsync(
186                selector: selector,
187                script: expression,
188                arg: ScriptsHelper.SerializedArgument(arg)).ConfigureAwait(false));
189
190        public async Task<T> EvalOnSelectorAsync<T>(string selector, string expression, object arg = null)
191            => ScriptsHelper.ParseEvaluateResult<T>(await _channel.EvalOnSelectorAsync(
192                selector: selector,
193                script: expression,
194                arg: ScriptsHelper.SerializedArgument(arg)).ConfigureAwait(false));
195
196        public async Task<T> EvalOnSelectorAllAsync<T>(string selector, string expression, object arg = null)
197            => ScriptsHelper.ParseEvaluateResult<T>(await _channel.EvalOnSelectorAllAsync(
198                selector: selector,
199                script: expression,
200                arg: ScriptsHelper.SerializedArgument(arg)).ConfigureAwait(false));
201
202        public Task FocusAsync() => _channel.FocusAsync();
203
204        public Task DispatchEventAsync(string type, object eventInit = null)
205            => _channel.DispatchEventAsync(
206                type,
207                eventInit = ScriptsHelper.SerializedArgument(eventInit));
208
209        public Task<string> GetAttributeAsync(string name) => _channel.GetAttributeAsync(name);
210
211        public Task<string> InnerHTMLAsync() => _channel.InnerHTMLAsync();
212
213        public Task<string> InnerTextAsync() => _channel.InnerTextAsync();
214
215        public Task<string> TextContentAsync() => _channel.TextContentAsync();
216
217        public Task SelectTextAsync(ElementHandleSelectTextOptions options = default)
218            => _channel.SelectTextAsync(options?.Force, options?.Timeout);
219
220        public Task<IReadOnlyList<string>> SelectOptionAsync(string values, ElementHandleSelectOptionOptions options = default)
221            => _channel.SelectOptionAsync(new[] { new SelectOptionValue() { Value = values } }, options?.NoWaitAfter, options?.Force, options?.Timeout);
222
223        public Task<IReadOnlyList<string>> SelectOptionAsync(IElementHandle values, ElementHandleSelectOptionOptions options = default)
224            => _channel.SelectOptionAsync(new[] { values }, options?.NoWaitAfter, options?.Force, options?.Timeout);
225
226        public Task<IReadOnlyList<string>> SelectOptionAsync(IEnumerable<string> values, ElementHandleSelectOptionOptions options = default)
227            => _channel.SelectOptionAsync(values.Select(x => new SelectOptionValue() { Value = x }), options?.NoWaitAfter, options?.Force, options?.Timeout);
228
229        public Task<IReadOnlyList<string>> SelectOptionAsync(SelectOptionValue values, ElementHandleSelectOptionOptions options = default)
230            => _channel.SelectOptionAsync(new[] { values }, options?.NoWaitAfter, options?.Force, options?.Timeout);
231
232        public Task<IReadOnlyList<string>> SelectOptionAsync(IEnumerable<IElementHandle> values, ElementHandleSelectOptionOptions options = default)
233            => _channel.SelectOptionAsync(values, options?.NoWaitAfter, options?.Force, options?.Timeout);
234
235        public Task<IReadOnlyList<string>> SelectOptionAsync(IEnumerable<SelectOptionValue> values, ElementHandleSelectOptionOptions options = default)
236            => _channel.SelectOptionAsync(values, options?.NoWaitAfter, options?.Force, options?.Timeout);
237
238        public Task CheckAsync(ElementHandleCheckOptions options = default)
239            => _channel.CheckAsync(
240                position: options?.Position,
241                timeout: options?.Timeout,
242                force: options?.Force,
243                noWaitAfter: options?.NoWaitAfter,
244                trial: options?.Trial);
245
246        public Task UncheckAsync(ElementHandleUncheckOptions options = default)
247            => _channel.UncheckAsync(
248                position: options?.Position,
249                timeout: options?.Timeout,
250                force: options?.Force,
251                noWaitAfter: options?.NoWaitAfter,
252                trial: options?.Trial);
253
254        public Task TapAsync(ElementHandleTapOptions options = default)
255            => _channel.TapAsync(
256                position: options?.Position,
257                modifiers: options?.Modifiers,
258                timeout: options?.Timeout,
259                force: options?.Force,
260                noWaitAfter: options?.NoWaitAfter,
261                trial: options?.Trial);
262
263        public Task<bool> IsCheckedAsync() => _channel.IsCheckedAsync();
264
265        public Task<bool> IsDisabledAsync() => _channel.IsDisabledAsync();
266
267        public Task<bool> IsEditableAsync() => _channel.IsEditableAsync();
268
269        public Task<bool> IsEnabledAsync() => _channel.IsEnabledAsync();
270
271        public Task<bool> IsHiddenAsync() => _channel.IsHiddenAsync();
272
273        public Task<bool> IsVisibleAsync() => _channel.IsVisibleAsync();
274
275        public Task<string> InputValueAsync(ElementHandleInputValueOptions options = null)
276            => _channel.InputValueAsync(options?.Timeout);
277
278        public Task SetCheckedAsync(bool checkedState, ElementHandleSetCheckedOptions options = null)
279             => checkedState
280             ? _channel.CheckAsync(
281                 position: options?.Position,
282                 timeout: options?.Timeout,
283                 force: options?.Force,
284                 noWaitAfter: options?.NoWaitAfter,
285                 trial: options?.Trial)
286             : _channel.UncheckAsync(
287                 position: options?.Position,
288                 timeout: options?.Timeout,
289                 force: options?.Force,
290                 noWaitAfter: options?.NoWaitAfter,
291                 trial: options?.Trial);
292
293        internal static ScreenshotType DetermineScreenshotType(string path)
294        {
295            string mimeType = path.MimeType();
296            return mimeType switch
297            {
298                "image/png" => ScreenshotType.Png,
299                "image/jpeg" => ScreenshotType.Jpeg,
300                _ => throw new ArgumentException($"path: unsupported mime type \"{mimeType}\""),
301            };
302        }
303    }
304}
305
Full Screen

ElementModel.cs

Source: ElementModel.cs Github

copy
1/*
2 * MIT License
3 *
4 * Copyright (c) Evgeny Nazarchuk.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25using Microsoft.Playwright;
26using Playwright.Synchronous;
27using System;
28using System.Collections.Generic;
29using System.Text.Json;
30
31namespace Playwright.PageObjectModel;
32
33public partial class ElementModel<TPageModel> : IElementModel, ITypedElementModel<TPageModel>
34    where TPageModel : PageModel
35{
36    public IPage Page { get; }
37
38    public IElementHandle Element { get; }
39
40    public TPageModel PageModel { get; }
41
42    public ElementModel(TPageModel pageModel, 
43        string selector, 
44        PageWaitForSelectorOptions? waitOptions = null, 
45        PageQuerySelectorOptions? queryOptions = null)
46    {
47        this.PageModel = pageModel;
48        this.PageModel.Page.WaitForSelector(selector, waitOptions);
49        this.Element = this.PageModel.Page.QuerySelector(selector, queryOptions)!;
50        this.PageModel = pageModel;
51        this.Page = this.PageModel.Page;
52    }
53
54    public ElementModel(ElementModel<TPageModel> parentElementModel, 
55        string selector, 
56        ElementHandleWaitForSelectorOptions? waitOptions = null)
57    {
58        this.Element = parentElementModel.GetElement(selector, waitOptions);
59        this.PageModel = parentElementModel.PageModel;
60        this.Page = this.PageModel.Page;
61    }
62
63    public ElementModel(TPageModel pageModel, IElementHandle element)
64    {
65        this.PageModel = pageModel;
66        this.Element = element;
67        this.Page = this.PageModel.Page;
68    }
69
70    public ElementModel(ElementModel<TPageModel> parenTElementModel, IElementHandle element)
71    {
72        this.PageModel = parenTElementModel.PageModel;
73        this.Element = element;
74        this.Page = this.PageModel.Page;
75    }
76
77    public TPageModel UpToPage()
78    {
79        return this.PageModel;
80    }
81
82    protected virtual IElementHandle GetElement(string selector, ElementHandleWaitForSelectorOptions? options = null)
83    {
84        this.Element.WaitForSelector(selector, options);
85        var element = this.Element.QuerySelector(selector);
86        return element!;
87    }
88
89    protected virtual IElementHandle? GetElementOrNull(string selector)
90    {
91        var element = this.Element.QuerySelector(selector);
92        return element;
93    }
94
95    protected virtual IReadOnlyList<IElementHandle> GetElements(string selector, ElementHandleWaitForSelectorOptions? options = null)
96    {
97        var elements = this.Element.QuerySelectorAll(selector);
98        return elements;
99    }
100
101    protected virtual TElementModel GetElementModel<TElementModel>(string selector)
102        where TElementModel : ITypedElementModel<TPageModel>
103    {
104        var blockType = typeof(TElementModel);
105        var ctorArgs = new[] { typeof(ElementModel<TPageModel>), typeof(string) };
106
107        var ctor = blockType.GetConstructor(ctorArgs);
108        if (ctor is null) throw new ApplicationException("Block Model not found");
109
110        var block = ctor.Invoke(new[] { this, (object)selector });
111        if (block is null) throw new ApplicationException("Block Model not created");
112
113        return (TElementModel)block;
114    }
115
116    protected virtual IReadOnlyCollection<TElementModel> GetElementModels<TElementModel>(string selector)
117        where TElementModel : ITypedElementModel<TPageModel>
118    {
119        var elements = this.Element.QuerySelectorAll(selector);
120        var blocks = new List<TElementModel>();
121
122        foreach (var element in elements)
123        {
124            var blockType = typeof(TElementModel);
125            var ctorArgs = new[] { this.GetType(), typeof(string) };
126            var ctor = blockType.GetConstructor(ctorArgs);
127            if (ctor is null) throw new ApplicationException("Block Model not found");
128
129            var block = ctor.Invoke(new[] { this, (object)selector });
130
131            blocks.Add((TElementModel)block);
132        }
133
134        return blocks;
135    }
136
137    protected virtual void Click(string? selector = null, ElementHandleClickOptions? options = null)
138    {
139        var element = selector is null ? this.Element : this.GetElement(selector);
140        element.Click(options);
141    }
142
143    protected virtual TReturnPage Click<TReturnPage>(string? selector = null, ElementHandleClickOptions? options = null)
144        where TReturnPage : PageModel
145    {
146        this.Click(selector, options);
147
148        var ctor = typeof(TReturnPage).GetConstructor(new[] { typeof(IPage) });
149        if (ctor is null) throw new ApplicationException("Page Model not found");
150        var returnPage = ctor.Invoke(new[] { this.PageModel.Page });
151        if (returnPage is null) throw new ApplicationException("Page Model not created");
152
153        return (TReturnPage)returnPage;
154    }
155
156    protected virtual void DbClick(string? selector = null, ElementHandleDblClickOptions? options = null)
157    {
158        var element = selector is null ? this.Element : this.GetElement(selector);
159        element.DblClick(options);
160    }
161
162    protected virtual void Hover(string? selector = null, ElementHandleHoverOptions? options = null)
163    {
164        var element = selector is null ? this.Element : this.GetElement(selector);
165        element.Hover(options);
166    }
167
168    protected virtual void ClearInput(string? selector = null)
169    {
170        var element = selector is null ? this.Element : this.GetElement(selector);
171        element.Evaluate("(element) => element.value =''", element);
172    }
173
174    protected virtual void Type(string? selector = null, string value = "", ElementHandleTypeOptions? options = null)
175    {
176        var element = selector is null ? this.Element : this.GetElement(selector);
177        element.Type(value, options);
178    }
179
180    protected virtual void Fill(string? selector = null, string value = "", ElementHandleFillOptions? options = null)
181    {
182        var element = selector is null ? this.Element : this.GetElement(selector);
183        element.Fill(value, options);
184    }
185
186    protected virtual void Check(string? selector = null, ElementHandleCheckOptions? options = null)
187    {
188        var element = selector is null ? this.Element : this.GetElement(selector);
189        element.Check(options);
190    }
191
192    protected virtual void Uncheck(string? selector = null, ElementHandleUncheckOptions? options = null)
193    {
194        var element = selector is null ? this.Element : this.GetElement(selector);
195        element.Uncheck(options);
196    }
197
198    protected virtual void Focus(string? selector = null)
199    {
200        var element = selector is null ? this.Element : this.GetElement(selector);
201        element.Focus();
202    }
203
204    protected virtual void Tap(string? selector = null, ElementHandleTapOptions? options = null)
205    {
206        var element = selector is null ? this.Element : this.GetElement(selector);
207        element.Tap(options);
208    }
209
210    protected virtual void Press(string key, string? selector = null, ElementHandlePressOptions? options = null)
211    {
212        var element = selector is null ? this.Element : this.GetElement(selector);
213        element.Press(key, options);
214    }
215
216    protected virtual void SelectText(string? selector = null, ElementHandleSelectTextOptions? options = null)
217    {
218        var element = selector is null ? this.Element : this.GetElement(selector);
219        element.SelectText(options);
220    }
221
222    protected virtual void SetChecked(bool checkedState, string? selector = null, ElementHandleSetCheckedOptions? options = null)
223    {
224        var element = selector is null ? this.Element : this.GetElement(selector);
225        element.SetChecked(checkedState);
226    }
227
228    protected virtual void SetInputFiles(string files, string? selector = null, ElementHandleSetInputFilesOptions? options = null)
229    {
230        var element = selector is null ? this.Element : this.GetElement(selector);
231        element.SetInputFiles(files, options);
232    }
233
234    protected virtual void SetInputFiles(FilePayload files, string? selector = null, ElementHandleSetInputFilesOptions? options = null)
235    {
236        var element = selector is null ? this.Element : this.GetElement(selector);
237        element.SetInputFiles(files, options);
238    }
239
240    protected virtual void SetInputFiles(IEnumerable<string> files, string? selector = null, ElementHandleSetInputFilesOptions? options = null)
241    {
242        var element = selector is null ? this.Element : this.GetElement(selector);
243        element.SetInputFiles(files, options);
244    }
245
246    protected virtual void SetInputFiles(IEnumerable<FilePayload> files, string? selector = null, ElementHandleSetInputFilesOptions? options = null)
247    {
248        var element = selector is null ? this.Element : this.GetElement(selector);
249        element.SetInputFiles(files, options);
250    }
251
252    protected virtual void SelectOption(string values, string? selector = null, ElementHandleSelectOptionOptions? options = null)
253    {
254        var element = selector is null ? this.Element : this.GetElement(selector);
255        element.SelectOption(values, options);
256    }
257
258    protected virtual void SelectOption(IElementHandle values, string? selector = null, ElementHandleSelectOptionOptions? options = null)
259    {
260        var element = selector is null ? this.Element : this.GetElement(selector);
261        element.SelectOption(values, options);
262    }
263
264    protected virtual void SelectOption(IEnumerable<string> values, string? selector = null, ElementHandleSelectOptionOptions? options = null)
265    {
266        var element = selector is null ? this.Element : this.GetElement(selector);
267        element.SelectOption(values, options);
268    }
269
270    protected virtual void SelectOption(SelectOptionValue values, string? selector = null, ElementHandleSelectOptionOptions? options = null)
271    {
272        var element = selector is null ? this.Element : this.GetElement(selector);
273        element.SelectOption(values, options);
274    }
275
276    protected virtual void SelectOption(IEnumerable<IElementHandle> values, string? selector = null, ElementHandleSelectOptionOptions? options = null)
277    {
278        var element = selector is null ? this.Element : this.GetElement(selector);
279        element.SelectOption(values, options);
280    }
281
282    protected virtual void SelectOption(IEnumerable<SelectOptionValue> values, string? selector = null, ElementHandleSelectOptionOptions? options = null)
283    {
284        var element = selector is null ? this.Element : this.GetElement(selector);
285        element.SelectOption(values, options);
286    }
287
288    protected virtual void ScrollIntoViewIfNeeded(string? selector = null, ElementHandleScrollIntoViewIfNeededOptions? options = null)
289    {
290        var element = selector is null ? this.Element : this.GetElement(selector);
291        element.ScrollIntoViewIfNeeded(options);
292    }
293
294    protected virtual void Screenshot(string? selector = null, ElementHandleScreenshotOptions? options = null)
295    {
296        var element = selector is null ? this.Element : this.GetElement(selector);
297        element.Screenshot(options);
298    }
299
300    protected virtual string TextContent(string? selector = null)
301    {
302        var element = selector is null ? this.Element : this.GetElement(selector);
303        return element.TextContent() ?? "";
304    }
305
306    protected virtual string InnerText(string? selector = null)
307    {
308        var element = selector is null ? this.Element : this.GetElement(selector);
309        return element.InnerText();
310    }
311
312    protected virtual string InnerHTML(string? selector = null)
313    {
314        var element = selector is null ? this.Element : this.GetElement(selector);
315        return element.InnerHTML();
316    }
317
318    protected virtual string InputValue(string? selector = null, ElementHandleInputValueOptions? options = null)
319    {
320        var element = selector is null ? this.Element : this.GetElement(selector);
321        return element.InputValue(options);
322    }
323
324    protected virtual bool IsChecked(string? selector = null)
325    {
326        var element = selector is null ? this.Element : this.GetElement(selector);
327        return element.IsChecked();
328    }
329
330    protected virtual bool IsDisabled(string? selector = null)
331    {
332        var element = selector is null ? this.Element : this.GetElement(selector);
333        return element.IsDisabled();
334    }
335
336    protected virtual bool IsEditable(string? selector = null)
337    {
338        var element = selector is null ? this.Element : this.GetElement(selector);
339        return element.IsEditable();
340    }
341
342    protected virtual bool IsEnabled(string? selector = null)
343    {
344        var element = selector is null ? this.Element : this.GetElement(selector);
345        return element.IsEnabled();
346    }
347
348    protected virtual bool IsHidden(string? selector = null)
349    {
350        var element = selector is null ? this.Element : this.GetElement(selector);
351        return element.IsHidden();
352    }
353
354    protected virtual bool IsVisible(string? selector = null)
355    {
356        var element = selector is null ? this.Element : this.GetElement(selector);
357        return element.IsVisible();
358    }
359
360    protected virtual ElementHandleBoundingBoxResult? BoundingBox(string? selector = null)
361    {
362        var element = selector is null ? this.Element : this.GetElement(selector);
363        return element.BoundingBox();
364    }
365
366    protected virtual IFrame? ContentFrame(string? selector = null)
367    {
368        var element = selector is null ? this.Element : this.GetElement(selector);
369        return element.ContentFrame();
370    }
371
372    protected virtual void DispatchEvent(string type, string? selector = null, object? eventInit = null)
373    {
374        var element = selector is null ? this.Element : this.GetElement(selector);
375        element.DispatchEvent(type);
376    }
377
378    protected virtual T EvalOnSelector<T>(string selector, string expression, object? arg = null)
379    {
380        return this.Element.EvalOnSelector<T>(selector, expression, arg);
381    }
382
383    protected virtual T EvalOnSelectorAll<T>(string selector, string expression, object? arg = null)
384    {
385        return this.Element.EvalOnSelectorAll<T>(selector, expression, arg);
386    }
387
388    protected virtual JsonElement? EvalOnSelector(string selector, string expression, object? arg = null)
389    {
390        return this.Element.EvalOnSelector(selector, expression, arg);
391    }
392
393    protected string? GetAttributeValue(string name, string? selector = null)
394    {
395        var element = selector is null ? this.Element : this.GetElement(selector);
396        return element.GetAttribute(name);
397    }
398
399    protected string GetComputedStyle(string name, string? selector = null)
400    {
401        var element = selector is null ? this.Element : GetElement(selector);
402        var value = Element.Evaluate<string>($"e => getComputedStyle(e).{name}", element);
403        return value;
404    }
405
406    protected virtual IFrame? OwnerFrame(string? selector = null)
407    {
408        var element = selector is null ? this.Element : this.GetElement(selector);
409        return element.OwnerFrame();
410    }
411}
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used methods in ElementHandleTapOptions

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)