Unable to locate anchor element(href) with javascript in webpage in selenium webdriver(chrome) -


i pretty new selenium. have referred previous posts , found out how click element using javascriptexecutor. unfortunately, not working , can;t going wrong. below code snippet , screenshots:

this how found out xpath in chrome:

code :

    @test public void search(){     try{          webelement element = driver.findelement(by.xpath("//a[contains(@href,\"javascript:__dopostback('lbsearch','')\")]"));         javascriptexecutor executor = (javascriptexecutor)driver;         executor.executescript("arguments[0].click()", element);     }     catch(exception e){         system.out.println("search element not found."+ e.getstacktrace());     } 

result :

thankx in advance!

instead of javascriptexecuter can click selenium function library.

your xpath //*[@id='lbsearch']

you can click using below code,

@test public void search(){      webelement element = null;     try{         element = driver.findelement(by.xpath("//*[@id='lbsearch']"));     }     catch(exception e){         system.out.println("search element not found."+ e.getstacktrace());     }     element.click(); } 

one more thing have use implicit , explicit wait locate element. this link you.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -