Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Need help with my selector in Selenium

I have no idea why it won't click on the button.

This is the code of the button:
[Image: 13Jm1Hi.png]

And this is my code:
Code
btnOrder = driver.find_element_by_class_name('js-shoppingcart-submit-button')
btnOrder.click()

Thanks.
You need the full class instead of just part
Looks like you're using only "js-shoppingcart-submit-button" which is not the full name of the class. You should be using its full name that includes the part from the line above it
(Nov 6, 2020 09:54 PM)Charger Wrote:  You need the full class instead of just part

(Nov 6, 2020 10:57 PM)TheGoobr Wrote:  Looks like you're using only "js-shoppingcart-submit-button" which is not the full name of the class. You should be using its full name that includes the part from the line above it

What if I only know a part of the class name that returns? And other stuff changes cause of mobile/desktop?
You need to find the element bu Xpath

//*[contains(@class, "js-shoppingcart-submit-button")]

This should work ^^^^^^^
(Nov 6, 2020 05:26 PM)Kαѕρer Wrote:  I have no idea why it won't click on the button.

This is the code of the button:
[Image: 13Jm1Hi.png]

And this is my code:
Code
btnOrder = driver.find_element_by_class_name('js-shoppingcart-submit-button')
btnOrder.click()

Thanks.

Code
driver.find_element_by_selector('SELECTOR_HERE').click()

is what i would use... or xpath. or, you could use the full class name not just the first portion.
"Give a Man a Fish, and You Feed Him for a Day. Teach a Man To Fish, and You Feed Him for a Lifetime"
Use xpath, here's a video on how to find it if you're unsure:
https://www.youtube.com/watch?v=jSiYpmvA50A

If the xpath changes depending on how the website is displayed, e.g pc/mobile, then use an if statement to decide which class you want selenium to use
If you ever have problems with Selenium, be it user-error or the site doing something tricky to make your job harder, you can just inject Javascript into the page.

Code
driver.execute_script(f'''
        {consts.SET_COUNTRY};
        document.getElementsByName("{consts.DOB_YEAR}")[0].value={random.randint(1975, 2001)};
        document.getElementsByName("{consts.DOB_MONTH}")[0].value={random.randint(1, 12)};
        document.getElementsByName("{consts.DOB_DAY}")[0].value={random.randint(1,28)};
        {consts.CONT_BUTTON_GO}
    ''')

Code
# - Every page
CONT_BUTTON_GO = 'document.getElementById("flow-form-submit-btn").click();'


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by Luffy-_-Aug 20, 2023 02:06 AM 12 445 Aug 20, 2023 02:06 AM
Last Post: Lucky4L
[Python] by Don CezarAug 20, 2023 01:37 AM 5 496 Aug 20, 2023 01:37 AM
Last Post: Lucky4L
by darkfantaOct 22, 2022 11:14 AM 6 364 Oct 22, 2022 11:14 AM
Last Post: darkfanta