使用 Selenium Python 时按钮没有点击并且没有错误

时间:2021-01-17 16:05:31

标签: python python-3.x selenium selenium-webdriver selenium-chromedriver

this buttons are not getting clicked

agree_button = driver.find_element_by_xpath('//*[@id="rightsDeclaration"]')
submit = driver.find_element_by_xpath('//*[@id="submit-work"]')

def upload():
  agree_button.click()
  time.sleep(1)
  submit.click()

upload():

但是我注意到当函数被调用时,url被这样选择:

Url selected when the function is called

我尝试使用 id、name、xpath、所有内容进行定位

按钮:

而且我还注意到页面向下滚动了一点(而不是点击 ofc),仅此而已。有什么问题?

完整代码:

copy_settings_link = "https://www.redbubble.com/portfolio/images/68171273-only-my-dog-understands-me-beagle-dog-owner-gift/duplicate"


def copy_settings():
    driver.get(copy_settings_link)

    replace_image_button = driver.find_element_by_xpath('//*[@id="select-image-base"]')

    time.sleep(1)

    replace_image_button.send_keys(Path_list[0])

    upload_check = driver.find_element_by_xpath(
        '//*[@id="add-new-work"]/div/div[1]/div[1]/div[1]/div')  # CHECKING UPLOAD
    while True:
        if upload_check.is_displayed() == True:
            print('Uploading...')
            time.sleep(1)
        else:
            print('Uploading Finished')
            time.sleep(1)
            break


copy_settings()


def upload():
    agree_button.click()
    time.sleep(1)
    submit.click()

upload()

1 个答案:

答案 0 :(得分:-1)

解决问题的家伙: 这个

chrome_options.add_argument("user-data-dir=C:\\Users\\Username\\AppData\\Local\\Google\\Chrome\\User Data") # Stay LOGGED IN

谁能向我解释一下这段代码是如何工作的?它让我在网站上保持登录状态

相关问题