How to use PressAsync method of Microsoft.Playwright.Core.Locator class

Best Playwright-dotnet code snippet using Microsoft.Playwright.Core.Locator.PressAsync

BotCore.cs

Source:BotCore.cs Github

copy

Full Screen

...492 .GetResult();493 if (_chatMessages.TryTake(out var message))494 {495 chatBox?.TypeAsync(message).GetAwaiter().GetResult();496 page.Keyboard.PressAsync("Enter").GetAwaiter().GetResult();497 }498 }499 catch (Exception)500 {501 //ignored 502 }503 }504 }505 if (itm.Service == StreamService.Service.Youtube)506 {507 Thread.Sleep(3000);508 try509 {510 var play = page.Locator(511 "xpath=/html/body/ytd-app/div/ytd-page-manager/ytd-watch-flexy/div[5]/div[1]/div/div[1]/div/div/div/ytd-player/div/div/div[5]/button");512 play?.ClickAsync().GetAwaiter().GetResult();513 }514 catch (Exception)515 {516 //ignored517 }518 while (true)519 {520 try521 {522 if (_firstPage)523 {524 firstPage = true;525 _firstPage = false;526 }527 if (firstPage)528 {529 var liveViewers = page.Locator(530 "xpath=/html/body/ytd-app/div/ytd-page-manager/ytd-watch-flexy/div[5]/div[1]/div/div[6]/div[2]/ytd-video-primary-info-renderer/div/div/div[1]/div[1]/ytd-video-view-count-renderer/span[1]");531 if (liveViewers.CountAsync().GetAwaiter().GetResult() > 0)532 {533 LiveViewer.Invoke(534 liveViewers.InnerTextAsync().GetAwaiter().GetResult().Split(' ')[0]);535 Thread.Sleep(5000);536 }537 }538 }539 catch (Exception)540 {541 LiveViewer.Invoke("N/A");542 }543 try544 {545 if (_refreshInterval != 0 &&546 DateTime.Now - startDate > TimeSpan.FromMinutes(_refreshInterval))547 {548 page.ReloadAsync().GetAwaiter().GetResult();549 startDate = DateTime.Now;550 }551 }552 catch553 {554 //ignored555 }556 }557 }558 if (itm.Service == StreamService.Service.DLive)559 {560 Thread.Sleep(3000);561 var isPlaying = false;562 while (true)563 {564 try565 {566 if (_firstPage)567 {568 firstPage = true;569 _firstPage = false;570 }571 if (firstPage)572 {573 try574 {575 var liveViewers =576 page.Locator(577 "xpath=/html/body/div/div[1]/div[20]/div[2]/div/div[2]/div/div/div/div[1]/div/div[1]/div[3]/div/div[1]/div/div[2]/div[2]");578 if (liveViewers.CountAsync().GetAwaiter().GetResult() > 0)579 {580 LiveViewer.Invoke(liveViewers.InnerTextAsync().GetAwaiter().GetResult()581 .Split(" ")[0]);582 Thread.Sleep(5000);583 }584 }585 catch (Exception)586 {587 //ignored588 }589 try590 {591 var liveViewers =592 page.Locator(593 "xpath=/html/body/div/div[1]/div[18]/div[2]/div/div/div/div/div/div/div/div/div[3]/div/div[3]/div/div/div[1]/div/div[1]/div[2]/div/div[1]/span");594 if (liveViewers.CountAsync().GetAwaiter().GetResult() > 0)595 {596 LiveViewer.Invoke(liveViewers.InnerTextAsync().GetAwaiter().GetResult());597 Thread.Sleep(5000);598 }599 }600 catch (Exception)601 {602 //ignored603 }604 }605 if (!isPlaying)606 {607 var play = page.Locator(608 "xpath=/html/body/div/div[1]/div[14]/div[2]/div/div[2]/div/div/div/div/div/div/div[1]/div/div/div/div/div[4]/div[2]/button/svg");609 if (play.CountAsync().GetAwaiter().GetResult() > 0)610 {611 Click(ref play);612 isPlaying = true;613 }614 }615 Thread.Sleep(1000);616 }617 catch (Exception)618 {619 //ignored620 }621 try622 {623 if (_refreshInterval != 0 &&624 DateTime.Now - startDate > TimeSpan.FromMinutes(_refreshInterval))625 {626 page.ReloadAsync().GetAwaiter().GetResult();627 isPlaying = false;628 startDate = DateTime.Now;629 }630 }631 catch (Exception)632 {633 //ignored634 }635 }636 }637 if (itm.Service == StreamService.Service.NimoTv)638 {639 Thread.Sleep(3000);640 var isPlaying = false;641 if (itm.LoginInfo != null)642 {643 Thread.Sleep(1000);644 var allCookies = GetCookie(itm.LoginInfo.Username);645 if (allCookies != null)646 foreach (var cookie in allCookies)647 {648 Cookie[] cookies =649 {650 new()651 {652 Domain = cookie.Domain, Expires = cookie.Expiry, Name = cookie.Name,653 Path = cookie.Path, Secure = cookie.Secure, Url = cookie.Path,654 HttpOnly = cookie.HttpOnly, Value = cookie.Value655 }656 };657 page.Context.AddCookiesAsync(cookies);658 }659 try660 {661 var loginButton =662 page.Locator("xpath=/html/body/div[2]/div[1]/div/div[2]/div/div[2]/button");663 if (loginButton.CountAsync().GetAwaiter().GetResult() > 0)664 {665 Click(ref loginButton);666 Thread.Sleep(1000);667 var usernameBox =668 page.Locator(669 "xpath=/html/body/div[6]/div/div[2]/div/div[2]/div/div/div[3]/div[1]/div[2]/input");670 if (usernameBox.CountAsync().GetAwaiter().GetResult() > 0)671 {672 Click(ref usernameBox);673 Thread.Sleep(1000);674 usernameBox.TypeAsync(itm.LoginInfo.Username.Split('/')[1]).GetAwaiter()675 .GetResult();676 var countryCodeArrow =677 page.Locator(678 "xpath=/html/body/div[6]/div/div[2]/div/div[2]/div/div/div[3]/div[1]/div[2]/div[1]");679 if (countryCodeArrow.CountAsync().GetAwaiter().GetResult() > 0)680 {681 Click(ref countryCodeArrow);682 Thread.Sleep(1000);683 var searchCountryCode =684 page.Locator(685 "xpath=/html/body/div[6]/div/div[2]/div/div[4]/div/div/div/div[1]/input");686 if (searchCountryCode.CountAsync().GetAwaiter().GetResult() > 0)687 {688 searchCountryCode.TypeAsync(itm.LoginInfo.Username.Split('/')[0]689 .Replace("+", string.Empty)).GetAwaiter().GetResult();690 Thread.Sleep(1000);691 var firstElement =692 page.Locator(693 "xpath=/html/body/div[6]/div/div[2]/div/div[4]/div/div/div/div[2]/div[1]/div[2]");694 if (firstElement.CountAsync().GetAwaiter().GetResult() > 0)695 Click(ref firstElement);696 }697 }698 var passwordBox =699 page.Locator(700 "xpath=/html/body/div[6]/div/div[2]/div/div[2]/div/div/div[3]/div[1]/div[3]/input");701 if (passwordBox.CountAsync().GetAwaiter().GetResult() > 0)702 {703 Click(ref passwordBox);704 Thread.Sleep(1000);705 passwordBox.TypeAsync(itm.LoginInfo.Password).GetAwaiter().GetResult();706 Thread.Sleep(1000);707 var login = page.Locator(708 "xpath=/html/body/div[6]/div/div[2]/div/div[2]/div/div/div[3]/div[1]/button");709 Thread.Sleep(1000);710 if (login.CountAsync().GetAwaiter().GetResult() > 0)711 Click(ref login);712 }713 }714 }715 }716 catch (Exception ex)717 {718 LogMessage?.Invoke(new Exception($"Login failed: {ex.Message}"));719 }720 while (true)721 {722 Thread.Sleep(1000);723 var cookie = page.Context.CookiesAsync().GetAwaiter().GetResult()724 .Any(x => x.Name == "userName");725 if (cookie)726 {727 StoreCookie(new Tuple<string, List<BrowserContextCookiesResult>>(itm.LoginInfo.Username,728 new List<BrowserContextCookiesResult>(page.Context.CookiesAsync().GetAwaiter()729 .GetResult().ToArray())));730 break;731 }732 }733 }734 while (true)735 {736 try737 {738 if (_firstPage)739 {740 firstPage = true;741 _firstPage = false;742 }743 if (firstPage)744 {745 var liveViewers =746 page.Locator(747 "xpath=/html/body/div[2]/div[2]/div[2]/div[1]/div/div/div[2]/div[2]/div[1]/div[1]/div/div[2]/div[3]/span");748 if (liveViewers.CountAsync().GetAwaiter().GetResult() > 0)749 {750 LiveViewer.Invoke(liveViewers.InnerTextAsync().GetAwaiter().GetResult());751 Thread.Sleep(5000);752 }753 }754 }755 catch (Exception)756 {757 LiveViewer.Invoke("N/A");758 }759 try760 {761 if (!isPlaying)762 {763 var play = page.Locator(764 "xpath=/html/body/div[2]/div[2]/div[2]/div[1]/div/div/div[2]/div[2]/div[1]/div[2]/div[1]/div[2]/div/span");765 if (play.CountAsync().GetAwaiter().GetResult() > 0)766 {767 Click(ref play);768 isPlaying = true;769 }770 }771 }772 catch (Exception)773 {774 //ignored775 }776 try777 {778 if (_refreshInterval != 0 &&779 DateTime.Now - startDate > TimeSpan.FromMinutes(_refreshInterval))780 {781 page.ReloadAsync().GetAwaiter().GetResult();782 isPlaying = false;783 startDate = DateTime.Now;784 }785 }786 catch (Exception)787 {788 //ignored789 }790 try791 {792 if (messageInterval != 0 &&793 DateTime.Now - messageStartDate > TimeSpan.FromMinutes(messageInterval) &&794 itm.LoginInfo != null)795 {796 SendMessage();797 messageStartDate = DateTime.Now;798 }799 }800 catch (Exception)801 {802 //ignored803 }804 void SendMessage()805 {806 try807 {808 var chatBox = page.WaitForSelectorAsync(".nimo-room__chatroom__chat-box__input")809 .GetAwaiter().GetResult();810 if (chatBox != null && _chatMessages.TryTake(out var message))811 {812 chatBox.TypeAsync(message).GetAwaiter().GetResult();813 page.Keyboard.PressAsync("Enter");814 }815 }816 catch (Exception)817 {818 //ignored 819 }820 }821 Thread.Sleep(1000);822 }823 }824 if (itm.Service == StreamService.Service.Twitter)825 {826 Thread.Sleep(3000);827 while (true)828 {829 try830 {831 if (_firstPage)832 {833 firstPage = true;834 _firstPage = false;835 }836 if (firstPage)837 {838 var liveViewers =839 page.Locator(840 "xpath=/html/body/div[2]/div[2]/div[2]/div[1]/div/div/div[2]/div[2]/div[1]/div[1]/div/div[2]/div[3]/span");841 if (liveViewers.CountAsync().GetAwaiter().GetResult() > 0)842 {843 LiveViewer.Invoke(liveViewers.InnerTextAsync().GetAwaiter().GetResult());844 Thread.Sleep(5000);845 }846 }847 }848 catch (Exception)849 {850 LiveViewer.Invoke("N/A");851 }852 try853 {854 if (_refreshInterval != 0 &&855 DateTime.Now - startDate > TimeSpan.FromMinutes(_refreshInterval))856 {857 page.ReloadAsync().GetAwaiter().GetResult();858 startDate = DateTime.Now;859 }860 }861 catch (Exception)862 {863 //ignored864 }865 Thread.Sleep(1000);866 }867 }868 if (itm.Service == StreamService.Service.Facebook)869 {870 Thread.Sleep(3000);871 if (itm.LoginInfo != null)872 {873 Thread.Sleep(1000);874 var allCookies = GetCookie(itm.LoginInfo.Username);875 if (allCookies != null)876 foreach (var cookie in allCookies)877 {878 Cookie[] cookies =879 {880 new()881 {882 Domain = cookie.Domain, Expires = cookie.Expiry, Name = cookie.Name,883 Path = cookie.Path, Secure = cookie.Secure, Url = cookie.Path,884 HttpOnly = cookie.HttpOnly, Value = cookie.Value885 }886 };887 page.Context.AddCookiesAsync(cookies);888 }889 try890 {891 var usernameBox =892 page.Locator(893 "xpath=/html/body/div[1]/div/div[1]/div/div[2]/div[2]/div[2]/div/form/div[2]/div[1]/label/input");894 if (usernameBox.CountAsync().GetAwaiter().GetResult() > 0)895 {896 Click(ref usernameBox);897 Thread.Sleep(1000);898 usernameBox.TypeAsync(itm.LoginInfo.Username).GetAwaiter().GetResult();899 var passwordBox =900 page.Locator(901 "xpath=/html/body/div[1]/div/div[1]/div/div[2]/div[2]/div[2]/div/form/div[2]/div[2]/label/input");902 if (passwordBox.CountAsync().GetAwaiter().GetResult() > 0)903 {904 Click(ref passwordBox);905 Thread.Sleep(1000);906 passwordBox.TypeAsync(itm.LoginInfo.Password).GetAwaiter().GetResult();907 Thread.Sleep(1000);908 var login = page.Locator(909 "xpath=/html/body/div[1]/div/div[1]/div/div[2]/div[2]/div[2]/div/form/div[2]/div[3]/div/div/div[1]/div/span/span");910 Thread.Sleep(1000);911 if (login.CountAsync().GetAwaiter().GetResult() > 0)912 Click(ref login);913 }914 }915 }916 catch (Exception ex)917 {918 LogMessage?.Invoke(new Exception($"Login failed: {ex.Message}"));919 }920 Thread.Sleep(3000);921 page.ReloadAsync().GetAwaiter().GetResult();922 while (true)923 {924 Thread.Sleep(1000);925 var cookie = page.Context.CookiesAsync().GetAwaiter().GetResult()926 .Any(x => x.Name == "c_user");927 if (cookie)928 {929 StoreCookie(new Tuple<string, List<BrowserContextCookiesResult>>(itm.LoginInfo.Username,930 new List<BrowserContextCookiesResult>(page.Context.CookiesAsync().GetAwaiter()931 .GetResult().ToArray())));932 break;933 }934 }935 }936 while (true)937 {938 try939 {940 if (_firstPage)941 {942 firstPage = true;943 _firstPage = false;944 }945 if (firstPage)946 {947 var liveViewers =948 page.Locator(949 "xpath=/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[1]/div[2]/div[1]/div/div/div/div[1]/div[1]/div/div/div/div[2]/div/div[5]/div[2]/span[2]");950 if (liveViewers.CountAsync().GetAwaiter().GetResult() > 0)951 {952 LiveViewer.Invoke(liveViewers.InnerTextAsync().GetAwaiter().GetResult());953 Thread.Sleep(5000);954 }955 }956 }957 catch (Exception)958 {959 //ignored960 }961 try962 {963 if (_refreshInterval != 0 &&964 DateTime.Now - startDate > TimeSpan.FromMinutes(_refreshInterval))965 {966 page.ReloadAsync().GetAwaiter().GetResult();967 startDate = DateTime.Now;968 }969 }970 catch (Exception)971 {972 //ignored973 }974 }975 }976 if (itm.Service == StreamService.Service.TrovoLive)977 {978 Thread.Sleep(5000);979 if (!Headless && !_useLowCpuRam)980 try981 {982 page.EvaluateAsync("window.localStorage.setItem('live/userClarityLevel', '" +983 itm.PreferredQuality + "');");984 page.ReloadAsync().GetAwaiter().GetResult();985 }986 catch (Exception)987 {988 //ignored989 }990 if (itm.LoginInfo != null)991 {992 Thread.Sleep(1000);993 var allCookies = GetCookie(itm.LoginInfo.Username);994 if (allCookies != null)995 foreach (var cookie in allCookies)996 {997 Cookie[] cookies =998 {999 new()1000 {1001 Domain = cookie.Domain, Expires = cookie.Expiry, Name = cookie.Name,1002 Path = cookie.Path, Secure = cookie.Secure, Url = cookie.Path,1003 HttpOnly = cookie.HttpOnly, Value = cookie.Value1004 }1005 };1006 page.Context.AddCookiesAsync(cookies);1007 }1008 try1009 {1010 var loginSignUpButton =1011 page.Locator("xpath=/html/body/div[1]/div/div/nav/div[3]/div[3]/button");1012 if (loginSignUpButton.CountAsync().GetAwaiter().GetResult() > 0)1013 {1014 Click(ref loginSignUpButton);1015 Thread.Sleep(4000);1016 ILocator usernameBox;1017 try1018 {1019 usernameBox =1020 page.Locator(1021 "xpath=/html/body/div[4]/div/div[2]/div[3]/div[1]/div[1]/div/input");1022 }1023 catch1024 {1025 usernameBox =1026 page.Locator(1027 "xpath=/html/body/div[4]/div/div[2]/div[3]/div[1]/div[1]/div[1]/input");1028 }1029 if (usernameBox.CountAsync().GetAwaiter().GetResult() > 0)1030 {1031 Click(ref usernameBox);1032 Thread.Sleep(1000);1033 usernameBox.TypeAsync(itm.LoginInfo.Username).GetAwaiter().GetResult();1034 Thread.Sleep(1000);1035 var passwordBox =1036 page.Locator(1037 "xpath=/html/body/div[4]/div/div[2]/div[3]/div[1]/div[3]/div/input");1038 if (passwordBox.CountAsync().GetAwaiter().GetResult() > 0)1039 {1040 passwordBox.TypeAsync(itm.LoginInfo.Password).GetAwaiter().GetResult();1041 var login = page.Locator(1042 "xpath=/html/body/div[4]/div/div[2]/div[3]/div[1]/button");1043 Thread.Sleep(1000);1044 if (login.CountAsync().GetAwaiter().GetResult() > 0)1045 Click(ref login);1046 }1047 }1048 }1049 }1050 catch (Exception ex)1051 {1052 LogMessage?.Invoke(new Exception($"Login failed: {ex.Message}"));1053 }1054 Thread.Sleep(3000);1055 page.ReloadAsync().GetAwaiter().GetResult();1056 while (true)1057 {1058 Thread.Sleep(1000);1059 var cookie = page.Context.CookiesAsync().GetAwaiter().GetResult().Any(x => x.Name == "uid");1060 if (cookie)1061 {1062 StoreCookie(new Tuple<string, List<BrowserContextCookiesResult>>(itm.LoginInfo.Username,1063 new List<BrowserContextCookiesResult>(page.Context.CookiesAsync().GetAwaiter()1064 .GetResult().ToArray())));1065 break;1066 }1067 }1068 }1069 var matureClicked = false;1070 var chatRulesClicked = false;1071 var matureCheckCount = 0;1072 while (true)1073 {1074 try1075 {1076 if (_firstPage)1077 {1078 firstPage = true;1079 _firstPage = false;1080 }1081 if (firstPage)1082 {1083 var liveViewers =1084 page.Locator(1085 "xpath=/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[1]/div[2]/div[1]/div/div/div/div[1]/div[1]/div/div/div/div[2]/div/div[5]/div[2]/span[2]");1086 if (liveViewers.CountAsync().GetAwaiter().GetResult() > 0)1087 {1088 LiveViewer.Invoke(liveViewers.InnerTextAsync().GetAwaiter().GetResult());1089 Thread.Sleep(5000);1090 }1091 }1092 }1093 catch (Exception)1094 {1095 //ignored1096 }1097 try1098 {1099 if (_refreshInterval != 0 &&1100 DateTime.Now - startDate > TimeSpan.FromMinutes(_refreshInterval))1101 {1102 page.ReloadAsync().GetAwaiter().GetResult();1103 startDate = DateTime.Now;1104 }1105 }1106 catch (Exception)1107 {1108 //ignored1109 }1110 try1111 {1112 if (!matureClicked && matureCheckCount < 5)1113 try1114 {1115 ILocator mature = null;1116 try1117 {1118 mature = page.Locator(1119 "xpath=/html/body/div[1]/div/div/div/div[2]/div/div/div[1]/div[1]/div[1]/div/div[4]/div[3]/section/div/button[2]");1120 }1121 catch1122 {1123 //ignored1124 }1125 if (mature.CountAsync().GetAwaiter().GetResult() == 0)1126 mature = page.Locator(1127 "xpath=/html/body/div[1]/div/div/div/div[2]/div/div/div[1]/div[1]/div[1]/div/div[2]/div[3]/section/div/button[2]");1128 if (mature.CountAsync().GetAwaiter().GetResult() > 0)1129 {1130 Click(ref mature);1131 matureClicked = true;1132 }1133 matureCheckCount++;1134 }1135 catch1136 {1137 //ignored because there is no mature button1138 }1139 }1140 catch (Exception)1141 {1142 // ignored1143 }1144 if (!chatRulesClicked)1145 try1146 {1147 var chatRules = page.Locator(1148 "xpath=/html/body/div[1]/div/div/div/div[2]/div/section/div[3]/div/section/section/div/button");1149 if (chatRules.CountAsync().GetAwaiter().GetResult() > 0)1150 {1151 chatRules.ClickAsync().GetAwaiter().GetResult();1152 chatRulesClicked = true;1153 }1154 }1155 catch (Exception)1156 {1157 //ignored1158 }1159 try1160 {1161 if (messageInterval != 0 &&1162 DateTime.Now - messageStartDate > TimeSpan.FromMinutes(messageInterval) &&1163 itm.LoginInfo != null)1164 {1165 SendMessage();1166 messageStartDate = DateTime.Now;1167 }1168 }1169 catch (Exception)1170 {1171 //ignored1172 }1173 void SendMessage()1174 {1175 try1176 {1177 var chatBox =1178 page.Locator(1179 "xpath=/html/body/div[1]/div/div/div/div[2]/div/section/div[3]/div/section/div[1]/div[1]/div[1]");1180 if (chatBox.CountAsync().GetAwaiter().GetResult() > 0 &&1181 _chatMessages.TryTake(out var message))1182 {1183 chatBox.TypeAsync(message).GetAwaiter().GetResult();1184 page.Keyboard.PressAsync("Enter");1185 }1186 }1187 catch (Exception)1188 {1189 //ignored 1190 }1191 }1192 Thread.Sleep(1000);1193 }1194 }1195 if (itm.Service == StreamService.Service.BigoLive)1196 {1197 Thread.Sleep(2000);1198 page.ReloadAsync().GetAwaiter().GetResult();...

Full Screen

Full Screen

Page.cs

Source:Page.cs Github

copy

Full Screen

...407 Timeout = options?.Timeout,408 Trial = options?.Trial,409 Strict = options?.Strict,410 });411 public Task PressAsync(string selector, string key, PagePressOptions options = default)412 => MainFrame.PressAsync(selector, key, new()413 {414 Delay = options?.Delay,415 NoWaitAfter = options?.NoWaitAfter,416 Timeout = options?.Timeout,417 Strict = options?.Strict,418 });419 public Task<IReadOnlyList<string>> SelectOptionAsync(string selector, string values, PageSelectOptionOptions options = default)420 => SelectOptionAsync(selector, new[] { values }, options);421 public Task<IReadOnlyList<string>> SelectOptionAsync(string selector, IEnumerable<string> values, PageSelectOptionOptions options = default)422 => SelectOptionAsync(selector, values.Select(x => new SelectOptionValue() { Value = x }), options);423 public Task<IReadOnlyList<string>> SelectOptionAsync(string selector, IElementHandle values, PageSelectOptionOptions options = default)424 => SelectOptionAsync(selector, new[] { values }, options);425 public Task<IReadOnlyList<string>> SelectOptionAsync(string selector, IEnumerable<IElementHandle> values, PageSelectOptionOptions options = default)426 => MainFrame.SelectOptionAsync(selector, values, new()...

Full Screen

Full Screen

Frame.cs

Source:Frame.cs Github

copy

Full Screen

...258 force: options?.Force,259 timeout: options?.Timeout,260 trial: options?.Trial,261 strict: options?.Strict);262 public Task PressAsync(string selector, string key, FramePressOptions options = default)263 => _channel.PressAsync(264 selector,265 key,266 delay: options?.Delay,267 timeout: options?.Timeout,268 noWaitAfter: options?.NoWaitAfter,269 strict: options?.Strict);270 public Task DispatchEventAsync(string selector, string type, object eventInit = default, FrameDispatchEventOptions options = default)271 => _channel.DispatchEventAsync(272 selector,273 type,274 ScriptsHelper.SerializedArgument(eventInit),275 options?.Timeout,276 options?.Strict);277 public Task FillAsync(string selector, string value, FrameFillOptions options = default)...

Full Screen

Full Screen

PageChannel.cs

Source:PageChannel.cs Github

copy

Full Screen

...251 {252 ["text"] = text,253 ["delay"] = delay,254 });255 internal Task PressAsync(string key, float? delay)256 => Connection.SendMessageToServerAsync(257 Guid,258 "keyboardPress",259 new Dictionary<string, object>260 {261 ["key"] = key,262 ["delay"] = delay,263 });264 internal Task InsertTextAsync(string text)265 => Connection.SendMessageToServerAsync(266 Guid,267 "keyboardInsertText",268 new Dictionary<string, object>269 {...

Full Screen

Full Screen

ElementHandleChannel.cs

Source:ElementHandleChannel.cs Github

copy

Full Screen

...350 ["noWaitAfter"] = noWaitAfter,351 };352 return Connection.SendMessageToServerAsync(Guid, "type", args);353 }354 internal Task PressAsync(string key, float? delay, float? timeout, bool? noWaitAfter)355 {356 var args = new Dictionary<string, object>357 {358 ["key"] = key,359 ["delay"] = delay,360 ["timeout"] = timeout,361 ["noWaitAfter"] = noWaitAfter,362 };363 return Connection.SendMessageToServerAsync(Guid, "press", args);364 }365 internal Task TapAsync(366 Position position,367 IEnumerable<KeyboardModifier> modifiers,368 float? timeout,...

Full Screen

Full Screen

Locator.cs

Source:Locator.cs Github

copy

Full Screen

...147 public Task<bool> IsVisibleAsync(LocatorIsVisibleOptions options = null)148 => _frame.IsVisibleAsync(_selector, ConvertOptions<FrameIsVisibleOptions>(options));149 public ILocator Nth(int index)150 => new Locator(_frame, $"{_selector} >> nth={index}");151 public Task PressAsync(string key, LocatorPressOptions options = null)152 => _frame.PressAsync(_selector, key, ConvertOptions<FramePressOptions>(options));153 public Task<byte[]> ScreenshotAsync(LocatorScreenshotOptions options = null)154 => WithElementAsync(async (h, o) => await h.ScreenshotAsync(ConvertOptions<ElementHandleScreenshotOptions>(o)).ConfigureAwait(false), options);155 public Task ScrollIntoViewIfNeededAsync(LocatorScrollIntoViewIfNeededOptions options = null)156 => WithElementAsync(async (h, o) => await h.ScrollIntoViewIfNeededAsync(ConvertOptions<ElementHandleScrollIntoViewIfNeededOptions>(o)).ConfigureAwait(false), options);157 public Task<IReadOnlyList<string>> SelectOptionAsync(string values, LocatorSelectOptionOptions options = null)158 => _frame.SelectOptionAsync(_selector, values, ConvertOptions<FrameSelectOptionOptions>(options));159 public Task<IReadOnlyList<string>> SelectOptionAsync(IElementHandle values, LocatorSelectOptionOptions options = null)160 => _frame.SelectOptionAsync(_selector, values, ConvertOptions<FrameSelectOptionOptions>(options));161 public Task<IReadOnlyList<string>> SelectOptionAsync(IEnumerable<string> values, LocatorSelectOptionOptions options = null)162 => _frame.SelectOptionAsync(_selector, values, ConvertOptions<FrameSelectOptionOptions>(options));163 public Task<IReadOnlyList<string>> SelectOptionAsync(SelectOptionValue values, LocatorSelectOptionOptions options = null)164 => _frame.SelectOptionAsync(_selector, values, ConvertOptions<FrameSelectOptionOptions>(options));165 public Task<IReadOnlyList<string>> SelectOptionAsync(IEnumerable<IElementHandle> values, LocatorSelectOptionOptions options = null)166 => _frame.SelectOptionAsync(_selector, values, ConvertOptions<FrameSelectOptionOptions>(options));...

Full Screen

Full Screen

PlaywrightIPhoneTest.cs

Source:PlaywrightIPhoneTest.cs Github

copy

Full Screen

...23 try {24 await page.GotoAsync("https://www.google.co.in/");25 await page.Locator("[aria-label='Search']").ClickAsync();26 await page.FillAsync("[aria-label='Search']", "BrowserStack");27 await page.Keyboard.PressAsync("Enter");28 await page.Locator("[aria-current='page']").WaitForAsync();29 var title = await page.TitleAsync();30 if (title == "BrowserStack - Google Search")31 {32 // following line of code is responsible for marking the status of the test on BrowserStack as 'passed'. You can use this code in your after hook after each test33 await MarkTestStatus("passed", "Title matched", page);34 } else {35 await MarkTestStatus("failed", "Title did not match", page);36 }37 }38 catch (Exception err) {39 await MarkTestStatus("failed", err.Message, page);40 }41 await browser.CloseAsync();...

Full Screen

Full Screen

PlaywrightPixelTest.cs

Source:PlaywrightPixelTest.cs Github

copy

Full Screen

...23 try {24 await page.GotoAsync("https://www.google.co.in/");25 await page.Locator("[aria-label='Search']").ClickAsync();26 await page.FillAsync("[aria-label='Search']", "BrowserStack");27 await page.Keyboard.PressAsync("Enter");28 await page.Locator("[aria-current='page']").WaitForAsync();29 var title = await page.TitleAsync();30 if (title == "BrowserStack - Google Search")31 {32 // following line of code is responsible for marking the status of the test on BrowserStack as 'passed'. You can use this code in your after hook after each test33 await MarkTestStatus("passed", "Title matched", page);34 } else {35 await MarkTestStatus("failed", "Title did not match", page);36 }37 }38 catch (Exception err) {39 await MarkTestStatus("failed", err.Message, page);40 }41 await browser.CloseAsync();...

Full Screen

Full Screen

PressAsync

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Microsoft.Playwright;7using Microsoft.Playwright.Core;8{9 {10 static async Task Main(string[] args)11 {12 using var playwright = await Playwright.CreateAsync();13 await using var browser = await playwright.Firefox.LaunchAsync(new BrowserTypeLaunchOptions14 {15 });16 var page = await browser.NewPageAsync();17 var searchBox = await page.QuerySelectorAsync("input[name='q']");18 await searchBox.TypeAsync("Hello World!");19 await searchBox.PressAsync("Enter");20 await page.WaitForLoadStateAsync(LoadState.DOMContentLoaded);21 await page.ScreenshotAsync("google.png");22 }23 }24}25using System;26using System.Collections.Generic;27using System.Linq;28using System.Text;29using System.Threading.Tasks;30using Microsoft.Playwright;31using Microsoft.Playwright.Core;32{33 {34 static async Task Main(string[] args)35 {36 using var playwright = await Playwright.CreateAsync();37 await using var browser = await playwright.Firefox.LaunchAsync(new BrowserTypeLaunchOptions38 {39 });40 var page = await browser.NewPageAsync();41 var searchBox = await page.QuerySelectorAsync("input[name='q']");42 await searchBox.TypeAsync("Hello World!");43 await searchBox.PressAsync("Enter");44 await page.WaitForNavigationAsync();45 await page.ScreenshotAsync("google.png");46 }47 }48}49using System;50using System.Collections.Generic;51using System.Linq;52using System.Text;53using System.Threading.Tasks;54using Microsoft.Playwright;55using Microsoft.Playwright.Core;56{57 {58 static async Task Main(string[] args)59 {60 using var playwright = await Playwright.CreateAsync();61 await using var browser = await playwright.Firefox.LaunchAsync(new BrowserTypeLaunchOptions62 {

Full Screen

Full Screen

PressAsync

Using AI Code Generation

copy

Full Screen

1using System;2using System.Threading.Tasks;3using Microsoft.Playwright;4{5 {6 static async Task Main(string[] args)7 {8 using var playwright = await Playwright.CreateAsync();9 await using var browser = await playwright.Chromium.LaunchAsync(new LaunchOptions10 {11 });12 var page = await browser.NewPageAsync();13 var locator = page.Locator("input[name=q]");14 await locator.FocusAsync();15 await locator.TypeAsync("Playwright");16 await locator.PressAsync("Enter");17 }18 }19}20using System;21using System.Threading.Tasks;22using Microsoft.Playwright;23{24 {25 static async Task Main(string[] args)26 {27 using var playwright = await Playwright.CreateAsync();28 await using var browser = await playwright.Chromium.LaunchAsync(new LaunchOptions29 {30 });31 var page = await browser.NewPageAsync();32 var locator = page.Locator("input[name=q]");33 await locator.FocusAsync();34 await locator.TypeAsync("Playwright");35 await page.Keyboard.PressAsync("Enter");36 }37 }38}

Full Screen

Full Screen

PressAsync

Using AI Code Generation

copy

Full Screen

1var locator = await page.QuerySelectorAsync("button");2await locator.PressAsync("Enter");3var elementHandle = await page.QuerySelectorAsync("button");4await elementHandle.PressAsync("Enter");5var frame = await page.QuerySelectorAsync("button");6await frame.PressAsync("Enter");7var page = await page.QuerySelectorAsync("button");8await page.PressAsync("Enter");9var worker = await page.QuerySelectorAsync("button");10await worker.PressAsync("Enter");11var jSHandle = await page.QuerySelectorAsync("button");12await jSHandle.PressAsync("Enter");13var browserContext = await page.QuerySelectorAsync("button");14await browserContext.PressAsync("Enter");15var browser = await page.QuerySelectorAsync("button");16await browser.PressAsync("Enter");17var playwright = await page.QuerySelectorAsync("button");18await playwright.PressAsync("Enter");19var channelOwner = await page.QuerySelectorAsync("button");20await channelOwner.PressAsync("Enter");21var iChannelOwner = await page.QuerySelectorAsync("button");22await iChannelOwner.PressAsync("Enter");23var iChannel = await page.QuerySelectorAsync("button");24await iChannel.PressAsync("Enter");25var iKeyboard = await page.QuerySelectorAsync("button");26await iKeyboard.PressAsync("Enter");

Full Screen

Full Screen

PressAsync

Using AI Code Generation

copy

Full Screen

1await page.WaitForLoadStateAsync(LoadState.DOMContentLoaded);2await page.Locator("button").PressAsync("Enter");3await page.WaitForLoadStateAsync(LoadState.DOMContentLoaded);4await page.Locator("button").ClickAsync();5await page.WaitForLoadStateAsync(LoadState.DOMContentLoaded);6await page.ClickAsync("button");7await page.WaitForLoadStateAsync(LoadState.DOMContentLoaded);8await page.ClickAsync("button", new() { Force = true });9await page.WaitForLoadStateAsync(LoadState.DOMContentLoaded);10await page.ClickAsync("button", new() { Force = true, Position = new() { X = 10, Y = 10 } });11await page.WaitForLoadStateAsync(LoadState.DOMContentLoaded);12await page.ClickAsync("button", new() { Force = true, Position = new() { X = 10, Y = 10 }, NoWaitAfter = true });13await page.WaitForLoadStateAsync(LoadState.DOMContentLoaded);14await page.ClickAsync("button", new() { Force = true, Position = new() { X = 10, Y = 10 }, NoWaitAfter = true, Timeout = 1000 });15await page.WaitForLoadStateAsync(LoadState.DOMContentLoaded);16await page.ClickAsync("button", new() {

Full Screen

Full Screen

PressAsync

Using AI Code Generation

copy

Full Screen

1await locator.PressAsync("Enter");2await locator.PressAsync("Delete");3await locator.PressAsync("Escape");4await locator.PressAsync("ArrowLeft");5await locator.PressAsync("ArrowRight");6await locator.PressAsync("ArrowUp");7await locator.PressAsync("ArrowDown");8await locator.PressAsync("PageUp");9await locator.PressAsync("PageDown");10await locator.PressAsync("Home");

Full Screen

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful