문제

I am testing an extjs web app by using robotframework and selenium2library, but I can not locate some HTML elements because they are assigned a dynamic id.

For example: selenium2library could not locate a button which html code like this:

<button type="button" id="ext-gen56" class=" x-btn-text silk-add">create vm</button>

I have tried to use detail XPath and css expression, but they do not work. How to deal with this problem? Any help would be appreciated.

What the tools I used are robotframework and selenium2library which are used for automatic web app testing.

Parts of my test script:

 // filename is A.txt
 //this is  a resource file including keywords which are used by testcase file 
*** Keywords *** 
open vmmanager page
    [Timeout]
    click element    xpath=//table[3]/tbody/tr[2]/td[2]/em/button

create vm
    [Arguments]    ${vm_name}    ${input_description}
    click element    xpath=//table[3]/tbody/tr[2]/td[2]/em/button
    click element    xpath=//td[2]/table/tbody/tr[2]/td[2]/em/button
    click link    xpath=//tbody/tr/td[5]/div/a
    click link    xpath=//tbody/tr/td[7]/div/a
    input text    xpath=//div/div/input    ${vm_name}
    click image    xpath=//div/div/img
    click element    xpath=//div[22]/div/div
    click image    xpath=//div[3]/div/div/img
    click element    xpath=//div[19]/div/div

name is null
    alert should be present    ${expect}
    click button    xpath=//div[2]/div/div/div/div/table/tbody/tr/td/em/button
    click button    xpath=//td[5]/table/tbody/tr[2]/td[2]/em/button

contact engineer
    alert should be present    
    click button    ext-gen311

//filename is B.txt
//this is testcase file
*** Settings ***
Resource       fiel A.txt   

*** Test Cases ***
VC_VM_01
    open vmmanager page
    create vm    ${empty}    description
    name is null

VC_VM_03
    open vmmanager page
    create vm    valentine    day
    contact engineer
도움이 되었습니까?

해결책

I would just find out how to set static ids. If you dont have access to the application code, I would ask that the developers would assign static ids for the components. - this would be IMHO the simplest solution.

Generated ids just usually mean that no one yet cares about them.

다른 팁

Without IDs, you could test using _near and _under from Sahi automation framework...I am using it, its Open Source..have patience to try different ways to identify the elements...its cool and good...

Most of the elements will be having text present on them.

xpath=//button[contains(text(), 'create vm')]

A generic approach will be

xpath=//*[contains(text(), 'create vm')]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top