Reputation: 964
I have reading several questions regarding the click isn't working, but still can't understand the real reason why it doesn't works. I'm basically waiting implicit that page loads, so then I can search for the close button of the modal. I have read that I need to enable javascript, but think this isn't necessary, according to the Selenium documention using the FF driver Runs in a real browser and supports JavaScript
private WebDriver driver;
public Test() {
System.setProperty("webdriver.gecko.driver", "geckodriver.exe");
driver =new ChromeDriver();
driver.get("https://www.site.site");
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
}
public void close50off(){
WebElement element = driver.findElement(By.className("close-button"));
if(element.isEnabled()){
element.click();
}
else{
System.out.println("Disable");
}
}
This is the HTML
<div class="close-button">
<a class="closeModal">
<img alt="Close Modal Button" style="border: 0;" src="/_ui/desktop/theme/images/close-button.png">
</a>
</div>
But it's giving me this error
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.29.461591 (62ebf098771772160f391d75e589dc567915b233), userDataDir=C:\Users\dturcios\AppData\Local\Temp\scoped_dir8916_4528}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=57.0.2987.133, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
Session ID: 5d9cf82fc240a40a7bf3245bb8b1ce6f
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:638)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:274)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
at testclasses.MyronTest.close50off(Test.java:38)
at seleniumproject1.SeleniumProject1.main(SeleniumProject1.java:32)
Upvotes: 0
Views: 165
Reputation: 2019
I got it. The class name you have mentioned belongs to the Div section of the html DOM. If you click the div section nothing will happen. We need to click on the hyperlink section of that Div which contains the tag name "a". So your code should be,
WebElement element = driver.findElement(By.className("closeModal"));
And, its better to mention the implicit wait above the driver.get("URL") line. Also, you have mentioned Gecko driver path in setproperty, but desired capabilities in Error is showing chromedriver 2.29. I hope you are having Global settings for chrome driver.
Upvotes: 0
Reputation: 3384
What you are doing wrong is; your initializing driver to Chromedriver
but in setProperty()
method you are setting path for geckodriver
so change that path to chromedriver as following:
System.setProperty("webdriver.chrome.driver", "your\path\to\chromedriver.exe");
if you wish to use firefox for testing then you need setting of path for gecko driver: and you can change your webdriver to :
driver =new FirefoxDriver();
Upvotes: 1