我正在通过日历小部件设置日期时间文本字段值.显然,日历小部件的功能如下:
document.getElementById('datetimetext').value = date_value;
Run Code Online (Sandbox Code Playgroud)
我想要的是:在更改日期时间文本字段中的值时,我需要重置页面中的其他一些字段.我已经在datetimetext字段中添加了一个onchange事件监听器,该字段没有被触发,因为我猜想onchange只有当元素获得焦点并且在失去焦点时其值被更改时才会触发.
因此,我正在寻找一种手动触发此onchange事件的方法(我想应该注意检查文本字段中的值差异).
有任何想法吗 ?
在官方W3c webdirver文档中,明确指出位置策略是:
State Keyword
CSS selector "css selector"
Link text selector "link text"
Partial link text selector "partial link text"
Tag name "tag name"
XPath selector "xpath"
Run Code Online (Sandbox Code Playgroud)
但是,Selenium的电线协议允许:
class name
css selector
id
name
link text
partial link text
tag name
xpath
Run Code Online (Sandbox Code Playgroud)
在理论中,Selenium的文档已经过时,"真实"的故事在新的规范文档中.然而...
我在最新的Chrome自己的Webdriver上运行了一些测试,我可以确认这一点,name并且class name两者都有效; 但是,它们不符合规格.
我记得在Chromium问题上阅读他们只会实现官方的Webdriver规范.
现在:我知道通用答案,其中"规格并不总是100%遵循"等.但是,我想知道的是:
javascript selenium google-chrome chromium chrome-web-driver
我正在使用 Selenium 和 Python 从我们的发电厂自动提取一些数据,现在我需要单击一个元素。问题是xpaths我们正在监控的每个工厂的元素和顺序都发生了变化。唯一的静态信息是value,就像在第三行中一样value="T_U0。
我尝试了很多方法,但找不到解决方案。我不能使用 index 或 child 因为参数的顺序正在改变。我尝试了 CSS 选择器但没有成功。
在这里你可以得到我的一些尝试......
driver.find_element_by_xpath("//input[@value='T_U0']").click()
driver.find_element_by_css_selector("input[@data-id-sys-abbreviation='388']").click()
Run Code Online (Sandbox Code Playgroud)
我尝试了很多其他的东西,但我只是拼命地尝试任何东西。
我真正需要的是一个find_by_value,如果有办法做到这一点,请告诉我,如果没有,请告诉我如何去做。
尝试使用 Selenium Webdriver 创建对象时出现以下错误。
"\selenium\webdriver\common\driver_finder.py", line 42, in get_path
path = SeleniumManager().driver_location(options) if path is None else path
"\selenium\webdriver\common\selenium_manager.py", line 74, in driver_location
browser = options.capabilities["browserName"]
AttributeError: 'str' object has no attribute 'capabilities'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
"\selenium_webdriver_webscraping.py", line 4, in <module>
driver = webdriver.Chrome(chrome_driver_path)
"\selenium\webdriver\chrome\webdriver.py", line 47, in __init__
self.service.path = DriverFinder.get_path(self.service, self.options)
"\selenium\webdriver\common\driver_finder.py", line 44, in get_path
raise NoSuchDriverException(f"Unable to obtain {service.path} using Selenium Manager; {err}")
selenium.common.exceptions.NoSuchDriverException: Message: …Run Code Online (Sandbox Code Playgroud) 我正在使用硒来抓取一些数据。
我点击的页面上有一个按钮说“custom_cols”。此按钮为我打开一个窗口,我可以在其中选择我的列。
这个新窗口有时需要一些时间才能打开(大约 5 秒)。所以为了处理这个我用过
WebDriverWait
Run Code Online (Sandbox Code Playgroud)
延迟为 20 秒。但有时它无法在新窗口中选择查找元素,即使该元素可见。这种情况只有十次发生一次,其余时间它都可以正常工作。
我也在其他地方使用了相同的功能(WebDriverWait),它按预期工作。我的意思是它会等到元素可见,然后在找到它的那一刻点击它。
我的问题是为什么即使我正在等待元素可见,新窗口上的元素也不可见。要在这里添加,我试图增加延迟时间,但我仍然偶尔会遇到该错误。
我的代码在这里
def wait_for_elem_xpath(self, delay = None, xpath = ""):
if delay is None:
delay = self.delay
try:
myElem = WebDriverWait(self.browser, delay).until(EC.presence_of_element_located((By.XPATH , xpath)))
except TimeoutException:
print ("xpath: Loading took too much time!")
return myElem
select_all_performance = '//*[@id="mks"]/body/div[7]/div[2]/div/div/div/div/div[2]/div/div[2]/div[2]/div/div[1]/div[1]/section/header/div'
self.wait_for_elem_xpath(xpath = select_all_performance).click()
Run Code Online (Sandbox Code Playgroud) python selenium web-scraping webdriverwait expected-condition
我正面临 python selenium 的问题,我在下面输入了代码,几分钟前它运行良好,但现在它不起作用,说无法访问 chrome 请帮助!
from selenium import webdriver
driver = webdriver.Chrome('/Users/Danny/Downloads/chromedriver_win32/chromedriver')
driver.get('https://google.com')
Run Code Online (Sandbox Code Playgroud)
结果
---------------------------------------------------------------------------
WebDriverException Traceback (most recent call last)
<ipython-input-36-6bcc3a6d3d05> in <module>()
----> 1 driver.get('https://google.com')
~\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py in get(self, url)
322 Loads a web page in the current browser session.
323 """
--> 324 self.execute(Command.GET, {'url': url})
325
326 @property
~\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py in execute(self, driver_command, params)
310 response = self.command_executor.execute(driver_command, params)
311 if response:
--> 312 self.error_handler.check_response(response)
313 response['value'] = self._unwrap_value(
314 response.get('value', None))
~\Anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py in check_response(self, response)
240 …Run Code Online (Sandbox Code Playgroud) 我不明白为什么我的代码总是出错
这是我的代码:
from selenium import webdriver
url = "https://google.com/"
path = "C:/Users/thefo/OneDrive/Desktop/summer 2023/chromedriver_win32"
driver = webdriver.Chrome(path)
driver.get(url)
Run Code Online (Sandbox Code Playgroud)
chromedriver的路径:

这是总是出现的错误:
Traceback (most recent call last):
File "C:\Users\thefo\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\common\driver_finder.py", line 42, in get_path
path = SeleniumManager().driver_location(options) if path is None else path
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\thefo\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\common\selenium_manager.py", line 74, in driver_location
browser = options.capabilities["browserName"]
^^^^^^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'capabilities'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Users\thefo\OneDrive\Desktop\summer 2023\Projeto Bot Discord - BUFF SELL CHECKER\teste2.py", …Run Code Online (Sandbox Code Playgroud) python selenium-chromedriver selenium-webdriver seleniummanager
首先,我一直在尝试从这个网页获取下拉列表:http : //solutions.3m.com/wps/portal/3M/en_US/Interconnect/Home/Products/ProductCatalog/Catalog/?PC_Z7_RJH9U5230O73D0ISNF9B3C3SI1000000_nid7WiJFRF7FPCX8F9100000000
这是我的代码:
import urllib2
from bs4 import BeautifulSoup
import re
from pprint import pprint
from selenium import webdriver
url = 'http://solutions.3m.com/wps/portal/3M/en_US/Interconnect/Home/Products/ProductCatalog/Catalog/?PC_Z7_RJH9U5230O73D0ISNF9B3C3SI1000000_nid=RFCNF5FK7WitWK7G49LP38glNZJXPCDXLDbl'
element_xpath = '//*[@id="Component1"]'
driver = webdriver.PhantomJS()
driver.get(url)
element = driver.find_element_by_xpath(element_xpath)
element_xpath = '/option[@value="02"]'
all_options = element.find_elements_by_tag_name("option")
for option in all_options:
print("Value is: %s" % option.get_attribute("value"))
option.click()
source = driver.page_source.encode('utf-8', 'ignore')
driver.quit()
source = str(source)
soup = BeautifulSoup(source, 'html.parser')
print soup
Run Code Online (Sandbox Code Playgroud)
打印出来的是这样的:
Traceback (most recent call last):
File "../../../../test.py", line 58, in <module>
Value is: XX
main() …Run Code Online (Sandbox Code Playgroud) python ×6
selenium ×5
javascript ×2
automation ×1
chromium ×1
exception ×1
select ×1
web-scraping ×1