0

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.

6
  • ng-click is an attribute of Angular and I doubt it will work like this. Did you check this? Commented Nov 8, 2018 at 16:28
  • I have used ng-click for the other buttons and it has worked just fine - that's why this is throwing me for a loop. Commented Nov 8, 2018 at 16:29
  • Oh sorry! I didn't look carefully earlier but there seems to be a problem with the quotes. Can you try this: browser.find_element_by_css_selector("button[ng-click=\"$ctrl.login('gatorlink')\"]").click(); Commented Nov 8, 2018 at 16:31
  • @Samarth With that, I get a ElementNotVisibleException. Is this because this button belongs to a dropdown menu? Your code finds the button but it says that it is not "interactable" Commented Nov 8, 2018 at 17:32
  • @hodsonus This sounds like an X-Y problem. Instead of asking for help with your solution to the problem, edit your question and ask about the actual problem. What are you trying to do? Commented Nov 8, 2018 at 17:51

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Accept the answer by clicking the tick mark next to the answer
0

Try using locator as browser.find_element_by_css_selector(button.md-button md-ink-ripple).click();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.