I checked your HTML code and the java code. I have found a few issues in the codes.
<div class="mbsc-sc-whl-sc" style="top: 0px; transform: translate3d(0px, -1520px, 0px); transition: -webkit-transform 300ms cubic-bezier(0.19, 1, 0.22, 1) 0s; margin-top: -80px;
In this line above you have not closed the <div>
tag
transform: translate3d(0px, -1520px, 0px);
this style and margin-top: -80px;
this attribute doesn't allow the text to be displayed within the visible area of the page. Hence Selenium isn't able to get the content of the <div>
tag.
Change it to,
<div class="mbsc-sc-whl-sc" style="top: 0px; transform: translate3d(0px, -1520px, 0px); transition: -webkit-transform 300ms cubic-bezier(0.19, 1, 0.22, 1) 0s; margin-top: -80px;>
Now about your java code:
driver.findElement(By.xpath("//div[@role='option']//*[@tabindex = '0']")).getText();
In this line above the Xpath is wrong and hence you are getting the error Unable to locate element".
Here is the correct xpath you can use: //div[@role='option' and @tabindex='0']
Here is my HTML with which I tested:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div class="mbsc-sc-whl-c" style="height:40px;margin-top:-21px;">
<div class="mbsc-sc-whl-sc" style="top: 0px; transition: -webkit-transform 300ms cubic-bezier(0.19, 1, 0.22, 1) 0s;">
<div role=" option" tabindex="-1" aria-selected="true" class="mbsc-sc-itm mbsc-btn-e mbsc-sc-itm-sel"
data-index="8" data-val="8" style="height:40px;line-height:40px;">08</div>
<div role="option" tabindex="0" aria-selected="true" class="mbsc-sc-itm mbsc-btn-e mbsc-sc-itm-sel"
data-index="9" data-val="9" style="height:40px;line-height:40px;">09
</div>
</div>
</div>
</body>
</html>
Here is my Java + Selenium code which worked for me:
try {
WebDriver driver;
System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir") + "//geckodriver");
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "FFLogs.txt");
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.get("http://localhost/1");
driver.manage().window().maximize();
Thread.sleep(2000);
String text = driver.findElement(By.xpath("//div[@role='option' and @tabindex='0']")).getText();
System.out.println("Your string: " + text);
String text1 = driver.findElement(By.xpath("//div[@role='option' and @tabindex='0']")).getAttribute("data-val");
System.out.println("Your attribute: " + text1);
Thread.sleep(5000);
driver.close();
} catch (Exception e) {
e.printStackTrace();
}