Ruby Watir Automation:无法找到google联系人输入字段并在其上设置值

问题描述 投票:2回答:1

这是添加新联系人时来自https://contacts.google.com/的表格

enter image description here

我试图通过xpath,通过类名,通过id,通过标签来定位它们,但是无法定位。以下是尝试通过xpath定位的示例

         browser.text_field(xpath: "//*[@id='c1']/div[2]/div[1]/div/div[1]/div/div[1]").set "#{firstname}"
         sleep (5)
         browser.text_field(xpath: "//*[@id='c1']/div[2]/div[3]/div/div[1]/div/div[1]/input").set "#{lastname}"
         sleep (5)
         browser.text_field(xpath: "//*[@id='c4']/div/div[1]/div/div[1]/div/div[1]/input").set "#{company}"
         sleep (5)
         browser.text_field(xpath: "//*[@id='c4']/div/div[2]/div/div[1]/div/div[1]/input").set "#{job}"
         sleep (5)
         browser.text_field(xpath: "//*[@id='c6']/div[1]/div[2]/div[1]/div/div[1]/input").set "#{number}"
         sleep (5)
         browser.text_field(xpath: "//*[@id='c15']/div/div[1]/div[2]/textarea").set "#{notes}"
         sleep (5)
         browser.div(xpath: "//*[@id='ow44']/div[3]/div/button[2]/div").wait_until(&:present?).click
ruby automation watir locate
1个回答
0
投票

输入字段的HTML看起来像:

<input type="text" class="whsOnd zHQkBf" jsname="YPqjbf" autocomplete="off" tabindex="0" aria-label="First name" autofocus="" data-initial-value="bbbb" badinput="false" dir="ltr">

请注意,有一个aria-label属性可提供对该字段的良好描述,这使其成为一个很好的定位器。

尝试:

browser.text_field(aria_label: 'First name').set "#{firstname}"

与其他字段类似。

© www.soinside.com 2019 - 2024. All rights reserved.