testing - Selenium, JAVA - how to find such element? -


do know how find , click @ element this:

<div class="offer ctrlopenofferinfo"> <a class="linkoffer" href="offer_view.html?id=1007"/> <p class="photo"> <p class="name">new offer</p> <p class="price">123</p> <div class="rate ctrlviewrateoffer" data-value="0.0000"> <p class="date"/> <div class="hide info"> <div class="bginfo"/> 

using selenium webdriver , using name of element there few similiar elements on page?

here's i've tired far:

webdriverwait wait = new webdriverwait(driver, 30); wait.until(expectedconditions.invisibilityofelementlocated(by.xpath("//*[text()='new offer']"))); wait.until(expectedconditions.elementtobeclickable(by.xpath(".//*[@id='formdevelopmentelementadd'][text()='new offer']"))); driver.findelement(by.xpath(".//*[@id='formdevelopmentelementadd']/div/p[2][text()='new offer']")).click(); 

or:

driver.findelement(by.xpath("//p[@class='name'][text()='new offer']")).click(); 

or:

string address = driver.findelement(by.xpath("//*[contains(text(), 'new offer') , @class='name']")).getattribute("href"); driver.get(baseurl + address); 

or:

driver.findelement(by.xpath("//a[text()='new offer']")).click(); 

i've tried these text, class, xpath...

assuming want click p tag containing new offer: think element not inside iframe. if so, must use driver.switchto().frame("name or xpath or css frame locator"); first before start looking element. now, how can find element. consider following options:

using xpath text based search

//p[.='new offer'] //to more precise can //p[@classs='name'][.='new offer'] 

you can use by.classname('name') identify element though name not unique me

using cssselector

.name

using nth-child() function of cssselector

.offer.ctrlopenofferinfo>a>p:nth-child(2)


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -