设想
Given I navigate to the table menu
When I click the "Add" button
And I fill "First name" with "Bob"
And I fill "Last name" with "Dylan"
And I click the "Create" button
Then I should see a new entry with a name of "Bob Dylan"
步骤定义
@step(u'I click the "(.*)" button')
def i_click_the_named_button(step, field):
button = world.browser.find_element_by_xpath('(//a[contains(text(),"{0}") and not(contains(@style, "display:none"))] | //input[@value="{0}" and not(contains(@style, "display:none"))] | //li[contains(text(), "{0}") and not(contains(@style, "display:none"))])[1]'.format(field))
button.click()
@step(u'I fill "(.*)" with "(.*)"')
def i_fill_in_field_with_value(step, field, value):
try:
label = world.browser.find_element_by_xpath('//label[contains(text(),"%s")]' % field)
id = label.get_attribute('for')
input = world.browser.find_element_by_id(id)
input.clear()
input.send_keys(value)
except:
input = world.browser.find_element_by_xpath('//input[@placeholder="%s"]' % field)
input.clear()
input.send_keys(value)
错误
NoSuchElementException:消息:u'没有这样的元素(会话信息:chrome=31.0.1650.63)(驱动程序信息:chromedriver=2.8.240825,平台=Linux 3.8.0-34-generic x86_64)'
描述
当点击“创建”按钮时,一个 div 元素被插入到 DOM(通过 JavaScript)中,显示“名字”和“姓氏”字段。在窗口可见的情况下运行时,我可以看到 div 元素在消失之前短暂出现并导致“我填充...”步骤失败。
从我读到的保持关注新创建的 div 元素的问题?
尝试的解决方案
- ActionChains(world.browser).move_to_element(button).click().perform()
- world.browser.switchTo() 和朋友们
- world.browser.find_element(...).send_keys("\n")
- sleep_until、implicitly_wait 等...
环境
- PyVirtualDisplay 0.1.2
- 硒 2.38.4
- 生菜 0.2.19
- Python 2.7.4
- Lubuntu Linux 13.10
研究