scrapy 杂剧作家:为什么显示“等待选择器可见”错误?

myss37ts  于 2022-11-09  发布在  其他
关注(0)|答案(2)|浏览(204)

我试图使用剧作家自动选择值。但它不是选择值。
正在等待选择器“(//选项[ @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>
xxls0lw8

xxls0lw81#

如果不知道目标页面是什么,很难说为什么一个E2E脚本会失败,但是看输出,问题似乎很明显。
您正尝试指向页面上的元素,但该元素当前处于隐藏状态(不可见)。请尝试调查发生这种情况的原因。

tkqqtvp1

tkqqtvp12#

如前所述,你试图选择一个不可见的元素。我试着跟随你的刮刀,如果我看页面“出租”的伦敦,有没有选项2000000在价格范围菜单。尝试设置为现有的值(40000),看看它是否工作。

相关问题