0

I am trying to automate a process of clicking some buttons. Although I have come really far and only 1 button that is not being able to work . I am using python with selenium. So I just want to click this button but I am unable to do so. Below is my code I have tried with css select and by xpath but Still I am unable to click it , I am getting error path not found.

This is the button that I want to click

<button class="yt-uix-button yt-uix-button-size-default yt-uix-button-primary  create-channel-submit" type="button" onclick=";return false;" data-channel-creation-token="GhaqucG9ARAKDi9teV92aWRlb3M_bz1VKAQ%3D"><span class="yt-uix-button-content">CREATE CHANNEL</span></button>

I have tried the following 2 codes but none of them work.

 driver.find_element_by_xpath("//button[@class='button.yt-uix-button yt-uix-button-size-default yt-uix-button-primary  create-channel-submit']").click()

driver.find_element_by_css_selector('button.yt-uix-button yt-uix-button-size-default yt-uix-button-primary  create-channel-submit').click()

5 Answers 5

6

Let's go over your attempts:

  • driver.find_element_by_xpath("//button[@class='button.yt-uix-button yt-uix-button-size-default yt-uix-button-primary create-channel-submit']").click()

    This one did not work because you are trying to put a CSS selector into a @class attribute value check. You meant to do something like:

    //button[@class='yt-uix-button yt-uix-button-size-default yt-uix-button-primary  create-channel-submit']
    
  • driver.find_element_by_css_selector('button.yt-uix-button yt-uix-button-size-default yt-uix-button-primary create-channel-submit').click()

    This one did not work since you are not specifying multiple classes in a CSS selector correctly, classes need to be separated with a dot:

    button.yt-uix-button.yt-uix-button-size-default.yt-uix-button-primary.create-channel-submit
    

Note that a much simpler selector should do the job - you don't have to specify all classes in a CSS selector - pick a more data-oriented and unique one, in this case I think this should be reasonably reliable and readable:

driver.find_element_by_css_selector('button.create-channel-submit').click()
Sign up to request clarification or add additional context in comments.

Comments

1

Assuming you want to click on the button CREATE CHANNEL you need to consider the presence of the <span> tag, within the <button> tag. You can use the following line of code:

driver.find_element_by_xpath("//button[@class='yt-uix-button yt-uix-button-size-default yt-uix-button-primary  create-channel-submit']/span[class='yt-uix-button-content']").click()

Comments

0

You can click on your element with next method:

driver.find_element_by_xpath("//span[(@class='yt-uix-button-content') and contains(text(), 'CREATE CHANNEL')]/..").click()

Comments

0

You can try this code

driver.find_element_by_css_selector('button.yt-uix-button.yt-uix-button-size-default.yt-uix-button-primary.create-channel-submit').click();

Comments

-2

can you try using by_class_name. You are using xpath and css to look up the class name

driver.find_element_by_class_name('yt-uix-button yt-uix-button-size-default yt-uix-button-primary  create-channel-submit')

1 Comment

You can't use compound class names with that method.

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.