我需要停止映射xpath中的元素,但是在映射下面的元素时遇到了问题。除了xpath之外,我无法获得任何其他映射方法。

我的主页http://drive-thru-hml.s3-website-us-west-2.amazonaws.com/login/primeiro-acesso
*带有映射元素的我的页面*
element :txt_cpf_branco, :xpath, '//*[@id="gatsby-focus-wrapper"]/div/div/div/main/div/div/div[2]/form/div[1]/div[1]/span'
element :txt_dtnasc_branco, :xpath, '//*[@id="gatsby-focus-wrapper"]/div/div/div/main/div/div/div[2]/form/div[1]/div[2]/span'
element :txt_nome_branco, :xpath, '//*[@id="gatsby-focus-wrapper"]/div/div/div/main/div/div/div[2]/form/div[1]/span[1]'
element :txt_cel_branco, :xpath, '//*[@id="gatsby-focus-wrapper"]/div/div/div/main/div/div/div[2]/form/div[1]/div[4]/span'
element :txt_email_branco, :xpath, '//*[@id="gatsby-focus-wrapper"]/div/div/div/main/div/div/div[2]/form/div[1]/span[2]'
element :txt_cep_branco, :xpath, '//*[@id="gatsby-focus-wrapper"]/div/div/div/main/div/div/div[2]/form/div[1]/span[3]'
element :txt_rua_branco, :xpath, '//*[@id="gatsby-focus-wrapper"]/div/div/div/main/div/div/div[2]/form/div[1]/span[4]'
element :txt_num_branco, :xpath, '//*[@id="gatsby-focus-wrapper"]/div/div/div/main/div/div/div[2]/form/div[1]/span[5]'
element :txt_bairro_branco, :xpath, '//*[@id="gatsby-focus-wrapper"]/div/div/div/main/div/div/div[2]/form/div[1]/span[6]'
element :txt_cidade_uf, :xpath, '//*[@id="gatsby-focus-wrapper"]/div/div/div/main/div/div/div[2]/form/div[1]/span[7]'发布于 2021-01-24 04:09:53
这个问题没有一个答案。这完全取决于您需要具体到什么程度,以及页面上有多少其他可能匹配的元素。您也没有说明您想要使用什么,而不是XPath,所以我假定使用CSS和text过滤器。一些潜在的选项可能是
element :txt_cpf_branco, :css, '#gatsby-focus-wrapper span', text: 'Preencha o CPF correto, por favor. Em caso de paciente menor de idade sem CPF, inclua o da pessoa responsável'或者,由于默认文本匹配是子字符串,因此您可以这样做
element :txt_cpf_branco, :css, '#gatsby-focus-wrapper span', text: 'Preencha o CPF correto'另外,由于:css是默认的选择器类型,因此通常可以将其删除
element :txt_cpf_branco, '#gatsby-focus-wrapper span', text: 'Preencha o CPF correto'如果您还想检查元素的类部分以缩小范围,可以将regexp传递给类过滤器
element :txt_cpf_branco, '#gatsby-focus-wrapper span', text: 'Preencha o CPF correto', class: /signUpFormFields__InputError\-/使用这些示例,您应该能够执行您希望更改的其余元素。在回答前面的一个问题时,您应该能够向element传递任何可以传递给Capybaras find方法的内容-https://www.rubydoc.info/github/jnicklas/capybara/Capybara/Node/Finders#find-instance_method -它包括文档中显示的所有标准选项以及任何选择器类型特定的选项( :css选择器类型没有任何额外的选项)
https://stackoverflow.com/questions/65863142
复制相似问题