Selenium是一种流行的开源工具,用于自动化Web浏览器。使用此标记时,还要包含您正在使用的特定组件的其他标记,例如selenium-webdriver用于语言绑定,selenium-ide,selenium-grid等。
我想发送包含4000多个字符的文本,当我这样做时 粉碎并继续打开新标签(idk为什么),但是当我尝试发送600个字符时,它可以正常工作。 B ...
可以在没有无头模式的情况下在Amazon EC2实例上运行硒?
我想使用硒在不使用无头模式的情况下在Amazon EC2实例上加载PDF页面,因为我想加载PDF。由于此处描述的问题(https://github.com/puppeteer/puppeteer/issues/
剪下python硒的iframe screenshots(chrome and firefox web驱动程序)
这里是我已经尝试过的事情的列表:
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import Select from selenium.common.exceptions import NoSuchElementException from selenium.webdriver.common.keys import Keys import unittest, time, re, getpass driver = webdriver.Firefox() driver.get("https://www.facebook.com/") someVariable = getpass.getpass("Press Enter after You are done logging in") driver.find_element_by_xpath('//*[@id="profile_pic_welcome_688052538"]').click()
当我用此命令在Maven中进行一次测试时: MVN测试-dtest = InitiatEteTest 我得到以下结果: 没有执行测试! 它在几分钟前起作用,但现在停止了...
我正在尝试刮擦一些Google数据,但我首先想单击Google弹出的“我同意”按钮。这是我用来这样做的脚本:
问题是硒似乎无法找到按钮,因此我会暂停错误。 (我也尝试使用find_element_by_xpath,但仍然无法正常工作)。
我一直在尝试使用Python Selenium为我观看YouTube视频并收集数据。
我必须从页面上的下拉列表中选择选项。我尝试了以下代码,但它显示了语法错误。有人可以帮我吗? web_element x = driver.find_element_by_xpath('//*[@ID =“
import time from bs4 import BeautifulSoup from selenium import webdriver from selenium.webdriver.firefox.options import Options def get_clip_link(link): try: url = link options = Options() options.add_argument('--headless') driver = webdriver.Firefox(options=options) driver.get(url) time.sleep(3) page = driver.page_source driver.quit() soup = BeautifulSoup(page, 'html.parser') videos = soup.find_all('video') for video in videos: src = video['src'] if src: return src else: return False except: return False
子Chromedriver“ get”不可靠地加载@Importfonts
@导入URL(https://fonts.googleapis.com/css?family = droid+serif:400,700, 我有一些html页面: </desc><code><!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style>@import url(https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic); body { font-family: 'Droid Serif'; }</style> </head> ... </code><question vote="4"> <p>用硒加载页面时:</p> <pre><code>from selenium import webdriver chrome_options = webdriver.ChromeOptions() chrome_options.add_argument('--kiosk-printing') browser = webdriver.Chrome(r"chromedriver.exe", options=chrome_options) browser.get("http://www.example.com/") </code></pre> <p>到达:</p> <pre> </pre>50%的时间,字体不会加载(页面上显示默认的serif字体(时代新罗马))<p> </p>50%的时间,字体已加载<ul> <li> </li><li>如何使字体加载使用硒更可靠? </li>第二次重新加载页面</ul><code>time.sleep(2); browser.get(...)</code><p>没有帮助100%的时间。 <strong> </strong> </p>i偶然发现了upoun这个web api(<p>https://developer.mozilla.org/en-us/docs/web/api/fontfaceset<pre>)。 </pre>步调此代码:</p> </question><code> from selenium import webdriver import time u = 'https://fonts.google.com/' driver = webdriver.Chrome(executable_path=r"chromedriver.exe") driver.maximize_window() driver.get(u) while True: script = '''return document.fonts.status;''' loaded = driver.execute_script(script) if loaded == 'loaded': print('All fonts loaded') break print('Fonts still loading') time.sleep(.5) </code><answer tick="false" vote="2"> <p>必须说,就我而言,铬只有在页面满载(包括字体)时将控件返回到硒。 也许您可以提供最低限度的例子来测试您的50-50场景<a href="https://developer.mozilla.org/en-US/docs/Web/API/FontFaceSet" rel="nofollow noreferrer"> </a> </p> <p>我正面临着同样的问题,什么也不会裁员。 这是我的情况:</p> <pre><code>html_string = render_to_string(self.template_name, ctx) html_string = html_string.encode('utf-8').decode('utf-8') temp_file = "/tmp/temp.html" [...] driver = webdriver.Chrome(options=options) driver.get("file://" + temp_file) [...] </code></pre> <p>没有任何东西会使字体加载。因此,我将它们复制到</p><code>/tmp</code></answer>目录中,以与<answer tick="false" vote="0"><code>.html</code><p></p>一起使用 <p><code># create directory in /tmp temp_fonts = Path("/tmp/fonts/") temp_fonts.mkdir(exist_ok=True) # loop through the fonts I am using in the .html for font in ['georgia-semibold.ttf', 'Nunito-Bold.ttf', 'Nunito-Regular.ttf']: with open(temp_fonts / font, "wb") as f: font_path = Path(settings.BASE_DIR) / "static" / "fonts" / font # copy the font into the /tmp/font directory f.write(open(font_path, "rb").read()) </code></p> <pre>现在参考文献无瑕 </pre> <p><pre>
open /#/login
该想法是创建一个bot来从聊天中读取消息,并且所有消息都在and(而不是必不可少的书写消息)中,例如 ul>lii从硒中找到<ul class="message-list"> <li class="message"> Hello There </li> <li class="message"> Hello </li> </ul> ,以处理是否存在/发现元素,但这始终是正确的,因为有一条消息,但是如果已经在聊天中,我不想继续代码,那不是主要想法。在那之后,我发现了expected_conditions,什么也没有。 EventFiringWebDriver, AbstractEventListener 我认为您可以编写一个循环,然后在循环中,在所需的“ ul”中获取“ li” s的数量。如果“李”的数量增加,您将有一个新消息。 from selenium import webdriver as wb from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support.events import EventFiringWebDriver, AbstractEventListener from selenium.webdriver.common.keys import Keys class MyListener(AbstractEventListener): def before_navigate_to(self, url, driver): print("Before navigate to %s" % url) def after_navigate_to(self, url, driver): print("After navigate to %s" % url) driver = wb.Chrome('C:\python\selenium\chromedriver.exe') wait = WebDriverWait(driver, 300) # ef_driver = EventFiringWebDriver(driver, MyListener()) driver.implicitly_wait(15) driver.get('https://socket.io/demos/chat/') driver.switch_to.frame(driver.find_element_by_class_name('iframe-class')) InputName = driver.find_element_by_xpath('/html/body/ul/li[2]/div/input') InputName.send_keys('MyNameIsJeff') InputName.send_keys(Keys.ENTER) 您可以在循环中进行某种侦听器,以检查消息元素的文本以确定它是否是新消息,您只需要确定要在“检查”之间等待的设定时间范围 - 10秒,30秒,1分钟等。 我认为您不需要活动的听众。您只需获取最新消息,然后继续检查它以查看它是否与以前的值不同。 # get list of li inside of ul ulList = driver.find_elements_by_xpath("//ul[@class='message-list']") lenOfLis = len(ulList) # wait for new message... while (true): ulList = driver.find_elements_by_xpath("//ul[@class='message-list']") if (len(ulList) > lenOfLis): # you have new message for (i in range(len(ulList)-lenOfLis)): yourLastMessage = ulList[-1-(i-1)] # you can do whatever you want with your last messages LenOfLis = len(ulList) # update length of ul # wait 15 seconds sleep(5) 此示例将获取当前显示的消息列表。然后,它抓住了最后一个收到的消息。该代码输入循环并重新查看消息列表,检查最后一个接收的消息,并将其文本与我们之前保存的最后一个消息值进行比较。 如果最后一个接收的消息与保存的值不同,则循环将断开,这意味着已经发布了新消息。 这里有一些不清楚的事情 - 最近的消息可能是list中的第一个元素或最后一个元素。另一个问题 - 您是否正在做一些事情来触发出现新消息?例如from time import sleep # get list of currently displayed messages messages = driver.find_elements_by_xpath("//li[@class='message']") # get text from most recent message # depending on element order on the page, might need to do messages.last last_message_text = messages[0].text # do something here to trigger a new message coming in? # wait for last_message_text to be something different while (true): # get list of currently displayed messages messages = driver.find_elements_by_xpath("//li[@class='message']") # new message has arrived if we hit this statement if (messages[0].text != last_message_text) break; # wait 15 seconds sleep(15) ?如果是这种情况,则代码的顺序可能需要更改。 lastly-在您的评论中,您提到有时是空的。我不太确定这是什么意思,但是如果某些消息出现并且页面上没有HTML,那么此解决方案将无法真正起作用。