i have followig html code , want x path text "analytics & research"
<div id="llcompositepagecontainer" class="column-wrapper"> <div id="compositepagetitlediv"> <h1 class="page-header">analytics & research</h1> </div>
i getting following xpath
using chrome, didnt work.
//*[@id="compositepagetitlediv"]
this code
webelement header = driver.findelement(by.xpath("//div[@id='llcompositepagecontainer']/div[@id='compositepagetitlediv']/h1[@class='page-header']")); string header2 = header.gettext(); system.out.println(header2);
and following error getting
exception in thread "main" org.openqa.selenium.nosuchelementexception: unable find element xpath == //div[@id='llcompositepagecontainer']/div[@id='compositepagetitlediv']/h1[@class='page-header'] (warning: server did not provide stacktrace information) command duration or timeout: 10.34 seconds documentation on error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
please try use below xpath:
driver.findelement(by.xpath(".//div[@id='compositepagetitlediv']/h1")).gettext();
if element inside iframe. use below code:
// switching frame driver.switchto().frame(<name>); // storing value of analytics & research string text = driver.findelement(by.xpath(".//div[@id='compositepagetitlediv']/h1")).gettext(); // switching original window driver.switchto().defaultcontent();
hope helps.
Comments
Post a Comment