Currently, I am in the process of setting up a Java program integrated with Selenium automation tool.
Upon the initiation of the program, a Chrome extension that is crucial for its functionality loads alongside the Chrome browser instance.
Following this, Chrome is expected to navigate to a specific webpage, select various elements on the page, and ultimately click a button that appears due to the presence of the extension.
The challenge arises when attempting to interact with this button, as it is dynamically generated by Javascript and lacks any identifiable ID attribute.
Upon inspecting the element, the following HTML snippet is revealed:
<a href="javascript:void(0);" class="selected button-task"
style="width: 140px; margin-left: 5px; height: 23px;">
<img src="websiteimage.png here" width="20px">Selected Task</a>
Unlike other clickable elements within the page that have distinctive types or IDs, this particular button does not. Nevertheless, interacting with it is crucial for the program's success. How should I proceed?
Upon attempting to locate and click the button using XPath, an error message is encountered:
Exception in thread "main" org.openqa.selenium.InvalidSelectorException: invalid selector:
Unable to locate an element with the xpath expression //a[contains@class,'selected'] and contains(@class, 'repost-selected button-task') and contains(text(), 'Repost Selected') because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document':
The string '//a[contains@class,'selected'] and contains(@class, 'repost-selected button-task') and contains(text(), 'Repost Selected')' is not a valid XPath expression.
I would greatly appreciate any guidance or suggestions on how to effectively handle this situation. Thank you!