I need to click this element and upload a document, but here the id of the button is generating dynamically.
Element:
<button class="md-raised md-primary e-button-small md-button md-ink-ripple" type="button" ng-transclude="" aria-label="Approve" data-ng-file-select="onFileSelect($files, rule)" data-accept="*/*" multiple="multiple" onclick="document.getElementById("--ng-file-upload-0.6873237604099194").click()" id="e--ng-file-upload-0.6873237604099194" style="overflow: hidden;">
<span class="ng-scope">Upload File</span>
<div class="md-ripple-container" style=""></div>
</button>
Tried to find and click in below ways:
driver.findElement(By.cssSelector("button[id^='e--ng-file-upload']]")).click();
driver.findElement(By.xpath("//button[contains(text(), 'Approve')]")).click();
- I looked here as well.
and getting this error every time:
org.openqa.selenium.InvalidSelectorException: invalid selector: An invalid or illegal selector was specified (Session info: chrome=60.0.3112.113) (Driver info: chromedriver=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41),platform=Windows NT 10.0.14393 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 104 milliseconds
You tried to get this item with text "Approve", but this is aria-label so you should do it like this using xpath (assuming that this is only button that have this label):
//button[@aria-label='Approve']
or with css selector:
button[aria-label=Approve]