2015-12-27 3 views
0

Я начал использовать Haskell и улучшил адаптацию к языку, который я хочу разработать, чтобы автоматизировать отправку информации на веб-сайт. Мне нужно имитировать щелчок, используя selenium webdriver. К сожалению, я застрял в ошибке, вызванной элементом, который я хочу щелкнуть, не будучи видимым. Как я могу изменить следующую видимость DIV с помощью команды Haskell WebDriver:Как изменить видимость с помощью Haskell webdriver

div id="DynObject129" 
    style="left: 3px; top: 47px; z-index: 1000; cursor: auto; 
      background-color: rgb(241, 239, 226); border-radius: 5px; 
      visibility: hidden; border-width: 2px; border-style: solid; 
      border-color: rgb(32, 107, 164); overflow: hidden; 
      position: absolute; width: 310px; height: 313px;" 

Исключение бросило после выполнения следующей команды:

pageItem <- findElem (ById "DynObject129") 
click pageItem 

ответ

0

Я не вижу какой-либо конкретные изменения, CSS материал в webdriver пакет, так что вы должны будете использовать швейцарский армейский нож они обеспечивают:

-- |An existential wrapper for any 'ToJSON' instance. This allows us to pass 
-- parameters of many different types to Javascript code. 
data JSArg = forall a. ToJSON a => JSArg a 

instance ToJSON JSArg where 
    toJSON (JSArg a) = toJSON a 

{- |Inject a snippet of Javascript into the page for execution in the 
context of the currently selected frame. The executed script is 
assumed to be synchronous and the result of evaluating the script is 
returned and converted to an instance of FromJSON. 

The first parameter defines a sequence of arguments to pass to the javascript 
function. Arguments of type Element will be converted to the 
corresponding DOM element. Likewise, any elements in the script result 
will be returned to the client as Elements. 

The second parameter defines the script itself in the form of a 
function body. The value returned by that function will be returned to 
the client. The function will be invoked with the provided argument 
list and the values may be accessed via the arguments object in the 
order specified. 
-} 
executeJS :: (F.Foldable f, FromJSON a, WebDriver wd) => f JSArg -> Text -> wd a 
executeJS a s = fromJSON' =<< getResult 
    where 
    getResult = doSessCommand methodPost "/execute" . pair ("args", "script") $ (F.toList a,s) 

Согласно этой документации, правильная команда что-то вроде:

executeJS [JSArg pageItem] "arguments[0].style.visibility = 'visible';" 

Это, конечно, не справиться с парой других обстоятельств: в первую очередь, когда элемент становится невидимым на display: none, а не visibility: hidden; для первого вам может потребоваться проверить, что веб-страница на самом деле делает с этими элементами, поскольку существует разница в стиле между display: block и display: inline, и вы не обязательно знаете, какая из них заставляет ссылку отображаться правильно.

+0

Привет, учитывая, что я сделал findElement и передавая результат в executeJS используя pageitem 'executeJS [pageItem]«аргументы [0] .style.visibility = „видимый“,»' Я использую GHCI, который бросает мне ошибка: Не удалось совместить ожидаемый тип JSArg с фактическим типом Элемент Первый параметр не должен преобразовывать элемент webdriver в элемент DOM и выполнять его успешно? Спасибо –

+0

@PedroSobreiro Извините, я ввернул это. Попробуйте '[JSArg pageItem]', а не просто 'pageItem'. –

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