【发布时间】:2022-01-23 14:41:21
【问题描述】:
我无法在 BDD 框架中单击 Selenium webdriver 上的按钮(保存)。
我可以点击通用脚本,但是当我通过 BDD 框架执行相同的脚本时它不起作用,请帮助我。
<button data-id="save-button" aria-label="Save" type="button" class="inline-flex items-center font-bold border rounded transition duration-300 ease-out hover:bg-primary-700 active:bg-primary-800 bg-primary-600 button-normal text-white justify-center text-base border-primary-600 px-4" style="background-image: linear-gradient(rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0));">Save</button>
我尝试过以下代码:
element = self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/div[1]/div/div[2]/div[2]/button[2]")
self.driver.execute_script("arguments[0].click();", element)
element = WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable(By.XPATH, "//button[text()='Clear all changes']/following::button[@data-id='save-button']")).click()
self.driver.execute_script("arguments[0].click();", element)
self.driver.find_element_by_xpath("/html/body/div[1]/div/div/div/div[1]/div/div[2]/div[2]/button[2]").click()
actions.click(self.driver.find_element_by_xpath("/html/body/div[1]/div/div/div/div[1]/div/div[2]/div[2]/button[2]")).perform()
actions.move_to_element(button).click(button).perform()
self.driver.find_element_by_class_name('inline-flex items-center font-bold border rounded transition duration-300 ease-out hover:bg-primary-700 active:bg-primary-800 bg-primary-600 button-normal text-white justify-center text-base border-primary-600 px-4').click()
ele =self.driver.find_element_by_css_selector("button[data-id='save-button']").click()
ele.click()
我在这个按钮上浪费了两天多。相同的元素可以在不使用任何框架的情况下正常执行脚本。
下面的工作脚本:
self.driver.find_element_by_xpath("/html/body/div[1]/div/div/div/div[1]/div/div[2]/div[2]/button[2]").click()
提前致谢。
【问题讨论】:
标签: python selenium xpath css-selectors webdriverwait