如何使剧作家在搜索栏中输入变量中的每个字符



有一个网站(公司网站-不能共享登录)有一个包含位置的搜索框

我正在使用填充从字典中输入一个随机选择的位置

剧作家一次性填写整个位置

,

但是如果你同时输入所有的字符串,网站搜索栏就会跳出来。

防止搜索栏跳出的唯一方法是在每个char中键入

。(我试着要求网站所有者修复搜索栏,他们似乎不感兴趣)

我累了,下面的代码,但它总是跳出

与搜索栏相关的代码部分

import random
import time
import sys
random10 = ""
lda_10 = {
1: "bahria town - overseas A",
2: "bahria town - awais qarni block",
3: "bahria town - shaheen block",
4: "bahria town - shaheen block extension",
5: "bahria town - Ghouri block",
6: "bahria town - takbeer block",
7: "bahria town - Gulbahar Block",
}
def R_10():
global random10
random10 = random.choice(list(lda_10.values()))
for l in random10:
sys.stdout.write(l)
sys.stdout.flush()
time.sleep(0.2)
page.locator("#location_id_input").fill(random10)
page.locator("(//ul)[8]/li[1]").click

我希望代码输入字符,但它就是不工作

您可以尝试使用page.type。它发送事件就像用户在键盘上打字一样,你也可以设置一个超时来模拟用户的延迟。

await page.type("#location_id_input", random10, {delay: 100}); 

最新更新