javascript - Find buttons (onclick) and click all of them -


i have trouble. im using java , webdriver. want go http://demo.opencart.com/, find "ipod", have 4 results, , want compare them (by clicking under each button "compare"), there 2 problem.

  1. how click on compare (there onclick)

    <button type="button" data-toggle="tooltip" title="" onclick="compare.add('48');" data-original-title="compare product"><i class="fa fa-exchange"></i></button>

  2. how compare search results?

you can try this:

    package pkyourpackage;      import java.util.list;      import org.openqa.selenium.by;     import org.openqa.selenium.javascriptexecutor;     import org.openqa.selenium.webdriver;     import org.openqa.selenium.webelement;     import org.openqa.selenium.chrome.chromedriver;       // http://demo.opencart.com/index.php?route=product/category&path=24      public class opencart_stackoverflow {         static webdriver driver;         public static void main(string[] args) {             system.setproperty("webdriver.chrome.driver", "c:/.....put_ path/chromedriver.exe");             driver = new chromedriver();              driver.get("http://demo.opencart.com/index.php?route=product/category&path=24");             try{thread.sleep(5000);}catch(exception e){}              list<webelement> list = driver.findelements(by.xpath("//button[contains(@data-original-title,'compare this')]/i"));             for(int = 0 ; < list.size() ; i++){                 list.get(i).click();                  try{thread.sleep(1500);}catch(exception e){}              }             try{thread.sleep(1500);}catch(exception e){}              // click on 'product comparison' compare             ((javascriptexecutor)driver).executescript("arguments[0].click();",driver.findelement(by.xpath("//*[contains(text(),'product comparison')]")));             try{thread.sleep(10000);}catch(exception e){}             driver.close();             driver.quit();          }     } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -