Finding element with no id, class or name (webdriver/Eclipse/Java/automation) -


i'm trying create basic login automated test submit button on page doesn't have unique class name, , id, how locate it?

the html button below:

<button class="btn btn-primary" type="submit" style="float:right;width:120px">sign in</button> 

there forgot password button shares same class different 'type':

<button class="btn btn-primary" type="button" style="float:left;width:140px;padding-left:10px" onclick="showforgotpassword()">forgotten password?</button> 

i have tried below code, didn't work me.

driver.findelement(by.classname("btn btn-primary")).click(); 

please if can guys, , forward hearing all.

xpath , firebug not related each other while running webdriver tests. can use xpath.

edited:

you can still test xpath expressions in firefox opening developer tools (press f12) -> click on console tab , enter expression using command $x("%xpath%"), in case command should so:

$x("//button[text()='sign in']") 

hit enter , see output array [element] in case 1 element mathces, array [element1, element2] if multiple matches found , array [ ] if nothing matches expression.

regarding how locate button, here few solutions:

1) (assuming id 'loginfield' provided id of login field) can use submit() method on element of login/password

// or reference login field did before, doesn't have id webelement loginfield = driver.findelement(by.id("loginfield")); loginfield.submit(); 

2) can call via xpath:

driver.findelement(by.xpath("//button[text()='sign in']")).click(); 

3) regarding classname - need use cssselector instead:

driver.findelement(by.cssselector("button.btn.btn-primary[type='submit']")).click(); 

this because classname doesn't work multiple classes, , when have space in class attribute of element means it's member of both "btn" , "btn-primary" classes, not it's member of "btn btn-primary" class.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -