0

use the python execute can find the element bottom and click, it works:

driver.execute_script("document.getElementsByClassName(\"g-c-R  webstore-test-button-label\")[0].click()")

but with the similar code, the python code can not work:

element_install_bottom=driver.find_element(by=By.ID, value=r'g-c-R  webstore-test-button-label')

and throw the exception:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="g-c-R  webstore-test-button-label"]"}

and have try by.ID, by.ClassName; but always throw the exception.

the whole code as below: from selenium import webdriver from selenium.webdriver.common.by import By import selenium.webdriver.support.ui as ui

import time

option = webdriver.ChromeOptions()

USER_DATA_PATH = r"D:\Chrome\User Data 3"
option.add_argument(f'--user-data-dir={USER_DATA_PATH}')
option.add_experimental_option('excludeSwitches', ['enable-automation'])

print(option.arguments)


driver = webdriver.Chrome(options=option)

extension_url = "https://chrome.google.com/webstore/detail/dark-reader/eimadpbcbfnmbkopoojfekhnkhdbieeh?hl=zh-CN"
driver.get(extension_url)
time.sleep(60)


element_install_bottom=driver.find_element(by=By.ID, value=r'g-c-R  webstore-test-button-label')
print(element_install_bottom)

1 Answer 1

1

You're seeing that exception as there is no element with that ID, that value is it's class.

Python:

driver.find_element_by_class_name("g-c-R  webstore-test-button-label")

or:

driver.find_element(By.CLASS_NAME, "g-c-R  webstore-test-button-label")
Sign up to request clarification or add additional context in comments.

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.