java - How come I am getting InvalidSelectorException when trying to click a button using Selenium? -
i new @ working selenium. trying click on following select button:
here code:
import org.openqa.selenium.by; import org.openqa.selenium.webdriver; import org.openqa.selenium.webelement; import org.openqa.selenium.firefox.firefoxdriver; public class firsttest { private static webdriver driver; public static void main(string[] args) throws exception { driver = new firefoxdriver(); driver.manage().window().maximize(); driver.navigate().to("http://www.metro.ca/flyer/index.en.html"); webelement postalcodeinputbox = driver.findelement(by.name("postalcode")); postalcodeinputbox.sendkeys("l6r1a1"); postalcodeinputbox.submit(); string pagesource = driver.getpagesource(); if(pagesource.contains("setstore btn")) system.out.println("setstore btn found"); webelement selectbutton = driver.findelement(by.classname("setstore btn")); selectbutton.click(); } }
picture confirming "setstore btn" in source:
here "setstore btn" in source:
it's caused trying search 2 separate classes in single by.classname(). "setstore" , "btn" each own classes.
try replacing
webelement selectbutton = driver.findelement(by.classname("setstore btn"));
with
webelement selectbutton = driver.findelement(new byall(by.classname("setstore"), by.classname("btn")));
alternatively, https://stackoverflow.com/a/16090160/1055102 provides option.
webelement selectbutton = driver.findelement(by.cssselector(".setstore.btn"));
Comments
Post a Comment