0

This Xpath and selector info copied from chrome elements inspector:

<button class="btn btn-white btn--no-margin btn--full-width _1XvaFLD3_IpAQNG-OJU2-H _1xNlj_ScH8hEMWzrkRt1A">Sign up</button>

CssSelector:

#main > div > div.Root__top-container.Root__top-container--has-notice-bar > div.Root__nav-bar.Root__nav-bar--has-notice-bar > nav > div.navBar-signupPrompt._3nonY0buM5Z1AF4aRrP8VY > p:nth-child(1) > button

That I have tried to find with:

button = wd.find_element(By.XPATH("//button[contains(text(),'"+btn-white+"')]"))

Which returns an error as:

NameError: name 'btn' is not defined

I found this that shows me how to find by a partial name.

Any help would be appreciated.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

3 Answers3

0

btn-white is a class in the button element, not a text. And you can't use it as a variable it need to be str parameter

button = wd.find_element_by_class_name('btn-white')

Or

button = wd.find_element(By.CLASS_NAME, 'btn-white')

If you want to locate by Sign up text

button = wd.find_element(By.XPATH, '//button[.="Sign up"]')
JaSON
  • 4,843
  • 2
  • 8
  • 15
Guy
  • 46,488
  • 10
  • 44
  • 88
  • Thanks! FYI the last solution 'locate by "Sign up" text returns an error: selenium.common.exceptions.WebDriverException: Message: unknown error: 'using' must be a string. Any ideas?? –  Dec 19 '18 at 17:06
  • @GregIven try with single parentheses `wd.find_element(By.XPATH, '//button[.="Sign up"]')` – Guy Dec 19 '18 at 18:55
-1

Does it work better for you?

button = wd.find_element(By.XPATH("//button[text()='Sign up']"))
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Xing-fu
  • 38
  • 9
-1

Try with :

wd.find_element(By.XPATH("//button[contains(text(),'Sign up')]"))
Ishita Shah
  • 3,955
  • 2
  • 27
  • 51