我试图使用剧作家自动选择值。但它不是选择值。
正在等待选择器“(//选项[ @Values ='2000000'])[2]”可见
显示此错误消息。2其背后的原因是什么?
def start_requests(self):
yield scrapy.Request(
url="https://www.rightmove.co.uk/",
callback = self.parse,
meta= dict(
playwright = True,
playwright_include_page = True,
playwright_page_coroutines = [
# setting location
PageCoroutine("fill", "//input[@name='typeAheadInputField']", 'london'),
# clicking 'For Rent' button
PageCoroutine("click", selector = "//button[@class='ksc_button large primary searchPanelControls '][1]"),
# selecting price range
PageCoroutine("wait_for_timeout", 3000),
PageCoroutine("wait_for_selector", "(//option[@value='2000000'])[2]"),
PageCoroutine("select_option", "(//select/option[@value='2000000'])[2]"),
# selecting bedroom range
PageCoroutine("wait_for_timeout", 3000),
PageCoroutine("wait_for_selector", "(//option[@value='5'])[1]"),
PageCoroutine("select_option", "(//select/option[@value='5'])[1]"),
# checking tick box
PageCoroutine("check", "//span[@class='tickbox--indicator']"),
PageCoroutine("wait_for_selector", "//span[@class='tickbox--indicator']"),
PageCoroutine("wait_for_timeout", 3000),
# clicking search button
PageCoroutine("click", "//button[@class='//button[@id='submit"),
PageCoroutine("wait_for_selector", "//button[@class='//button[@id='submit"),
PageCoroutine("wait_for_timeout", 3000)
]
)
)
return super().start_requests()
输出
playwright._impl._api_types.TimeoutError: Timeout 30000ms exceeded.
=========================== logs ===========================
waiting for selector "(//option[@value='2000000'])[2]" to be visible
selector resolved to hidden <option value="2000000">2,000,000</option>
2条答案
按热度按时间xxls0lw81#
如果不知道目标页面是什么,很难说为什么一个E2E脚本会失败,但是看输出,问题似乎很明显。
您正尝试指向页面上的元素,但该元素当前处于隐藏状态(不可见)。请尝试调查发生这种情况的原因。
tkqqtvp12#
如前所述,你试图选择一个不可见的元素。我试着跟随你的刮刀,如果我看页面“出租”的伦敦,有没有选项2000000在价格范围菜单。尝试设置为现有的值(40000),看看它是否工作。