我正在尝试使用Selenium Webdriver单击按钮。但是无法识别按钮。 这是我的代码:它返回错误消息
NoSuchElementException:消息:没有这样的元素:无法找到元素:{“ method”:“ xpath”,“ selector”:“ // * [@ id =” artifactContentList“] / div [2] / div / div [3] / content-dataset-actions / content-dataset-actions / section / section / button [2]“} \ n(会话信息:headless chrome = 81.0.4044.138)\ n(驱动程序信息:chromedriver = 2.39 .562718(9a2698cba08cf5a471a29d30c8b3e12becabb0e9),platform = Windows NT 10.0.18363 x86_64)'
function loadScript(script, callback) {
const dom = document.createElement('script');
if (callback) dom.onload = callback;
dom.type = (script.type) ? script.type : 'text/javascript';
if (typeof (script) === 'object') {
if (script.src) dom.src = script.src;
if (script.integrity) dom.integrity = script.integrity;
if (script.crossorigin) dom.crossOrigin = script.crossorigin;
} else if (typeof (script) === 'string') {
dom.src = script;
}
document.getElementsByTagName('head')[0].appendChild(dom, document.currentScript);
}
loadScript({ src: '<%= BASE_URL %>js/DependencyInterface.js' }, function () {
// Your code here...
});
这是完整的元素:
from selenium.webdriver.chrome.options import Options
from splinter import Browser
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import csv
chrome_options = Options()
chrome_options.add_argument("--headless")
browser = webdriver.Chrome(executable_path= "C:\chromedriver\chromedriver.exe", chrome_options=chrome_options)
def open_url():
browser = webdriver.Chrome(executable_path= "C:\chromedriver\chromedriver.exe", chrome_options=chrome_options)
browser.get("https://app.powerbi.com/groups/xxxxs")
python_button = browser.find_element_by_xpath('/html/body/div[1]/root-downgrade/mat-sidenav-container/mat-sidenav-content/div/landing/div/div/div/ng-transclude/landing-route/list-proxy/content-list/div/main/dataset-list/div/virtual-scroll/div[2]/div/div[3]/content-dataset-actions/content-dataset-actions/section/section/button[2]')
print(python_button)
python_button.click()
browser.quit()
open_url()
答案 0 :(得分:0)
尝试一下:
python_button = browser.find_element_by_class_name('refreshNow')