2014-01-07 4 views
0

СценарийСалаты/Селен удаление вновь созданного DOM элементов

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» нет такого элемента (информация о сессии: хром = 31.0.1650.63) (информация Driver: chromedriver = 2.8.240825, платформа = Linux 3.8.0-34-родовой x86_64) '

Описание

При нажатии кнопки «Создать» в DOM (через JavaScript) добавляется элемент div, отображающий поля «Имя» и «Фамилия». При работе с видимым окном я вижу, как элемент div появляется кратковременно, прежде чем исчезнуть, и приведет к ошибкам «Я заполняю ...».

Из того, что я прочитал, это проблема с поддержанием сосредоточения на вновь созданном элементе div?

Solutions Покушение

  • ActionChains (world.browser) .move_to_element (кнопка) .click(). (Выполнить)
  • world.browser.switchTo() и друзей
  • мира. browser.find_element (...). send_keys ("\ п")
  • sleep_until, implicitly_wait и т.д ...

Environment

  • PyVirtualDisplay 0.1.2
  • Селен 2.38.4
  • латук 0.2.19
  • Python 2.7.4
  • Lubuntu Linux 13.10

Исследование

Keeping the focus after opening a new window in the Selenium IDE

Using Python bindings, Selenium WebDriver click() is not working sometimes.

How to switch to the new browser window, which opens after click on the button?

Selenium WebDriver ActionChains

WebDriver.py implementation

Selenium API

ответ

0

Я не знаю, почему это устранит проблему, но она действительно помогла.

@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() 
    time.sleep(1) 
+0

После того, как латту «Я нажимаю» сразу же называет следующий шаг, но браузер, возможно, еще не отобразил новые элементы. Салат и селен могут работать быстрее, чем браузер. – PukeCloud

Смежные вопросы