Reputation: 41
I am building a python3 web bot using selenium-webdriver and don't have too much experience with selenium. I am getting an exception, "selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: An invalid or illegal selector was specified", because of this line of code:
browser.find_element_by_css_selector("button[ng-click='$ctrl.login('gatorlink')']").click();
I'm fairly certain it's related to the single quotes surrounding the string "gatorlink", but I am really not sure. I know the selector is not correct. This is the button I am trying to click.
<button class="md-button md-ink-ripple" type="button" ng-transclude="" ng-click="$ctrl.login('gatorlink')" role="menuitem">
<md-icon class="ng-scope material-icons" role="img" aria-label="exit_to_app">exit_to_app</md-icon>
<span class="ng-scope">Log in with GatorLink</span>
</button>
It's in a drop down and I am able to open the menu but not click this button at the moment.
Upvotes: 0
Views: 1688
Reputation: 8479
You have single quotes inside single quotes, it is invalid selector.
You need to escape the single quotes.
browser.find_element_by_css_selector("button[ng-click='$ctrl.login(\\'gatorlink\\')']").click()
It works now and finding the element.
Upvotes: 2
Reputation: 324
Try using locator as browser.find_element_by_css_selector(button.md-button md-ink-ripple).click();
Upvotes: 0