启动功能时
def run(driver_path):
driver = webdriver.Chrome(executable_path=driver_path)
driver.get('https://tproger.ru/quiz/real-programmer/')
button = driver.find_element_by_class_name("quiz_button")
button.click()
run(driver_path)
Run Code Online (Sandbox Code Playgroud)
我收到这样的错误:
def run(driver_path):
driver = webdriver.Chrome(executable_path=driver_path)
driver.get('https://tproger.ru/quiz/real-programmer/')
button = driver.find_element_by_class_name("quiz_button")
button.click()
run(driver_path)
Run Code Online (Sandbox Code Playgroud)
...但我不明白为什么。
我正在为我的 Chrome 版本使用最新版本的WebDriver 。我不知道为什么我得到
<ipython-input-27-c5a7960e105f>:6: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
driver = webdriver.Chrome(executable_path=driver_path)
<ipython-input-27-c5a7960e105f>:10: DeprecationWarning: find_element_by_* commands are deprecated. Please use find_element() instead
button = driver.find_element_by_class_name("quiz_button")
Run Code Online (Sandbox Code Playgroud)
...当文档中存在该命令时。
我用python,selenium和firefox运行这段代码,但仍然得到firefox的'head'版本:
binary = FirefoxBinary('C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe', log_file=sys.stdout)
binary.add_command_line_options('-headless')
self.driver = webdriver.Firefox(firefox_binary=binary)
Run Code Online (Sandbox Code Playgroud)
我也尝试了二进制的一些变体:
binary = FirefoxBinary('C:\\Program Files\\Nightly\\firefox.exe', log_file=sys.stdout)
binary.add_command_line_options("--headless")
Run Code Online (Sandbox Code Playgroud) python selenium python-3.x selenium-webdriver firefox-headless
如何使用带有Python的Selenium模块在变量中获取HTML源代码?
我想做这样的事情:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get(raw_input("Enter URL: "))
if "whatever" in html_source:
# Do something
else:
# Do something else
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?我不知道如何访问HTML源代码.
我有情况,当点击按钮打开带有搜索结果的新浏览器窗口时.
有没有办法连接并专注于新打开的浏览器窗口?
并使用它,然后返回到原始(第一)窗口.
我正在尝试选择一个选项进行网络测试.可以在此处找到一个示例:http://www.tizag.com/phpT/examples/formex.php
除了选择选项部分外,一切都很好.如何按值或按标签选择选项?
我的代码:
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium;
using System.Collections.ObjectModel;
using System.Text.RegularExpressions;
using System.Threading;
using System.Diagnostics;
using System.Runtime.InteropServices;
class GoogleSuggest
{
static void Main()
{
IWebDriver driver = new FirefoxDriver();
//Notice navigation is slightly different than the Java version
//This is because 'get' is a keyword in C#
driver.Navigate().GoToUrl("http://www.tizag.com/phpT/examples/formex.php");
IWebElement query = driver.FindElement(By.Name("Fname"));
query.SendKeys("John");
driver.FindElement(By.Name("Lname")).SendKeys("Doe");
driver.FindElement(By.XPath("//input[@name='gender' and @value='Male']")).Click();
driver.FindElement(By.XPath("//input[@name='food[]' and @value='Chicken']")).Click();
driver.FindElement(By.Name("quote")).Clear();
driver.FindElement(By.Name("quote")).SendKeys("Be Present!");
driver.FindElement(By.Name("education")).SendKeys(Keys.Down + Keys.Enter); // working but that's not what i was looking for
// …Run Code Online (Sandbox Code Playgroud) from selenium import webdriver
import time
test = webdriver.Chrome()
test.get('https://docs.google.com/forms/d/e/1FAIpQLSeYUmAYYZNtbU8t8MRxwJo- d1zkmSaEHodJXs78RzoG0yFY2w/viewform')
time.sleep(5)
Name = 'kuch bhi'
last = test.find_element_by_xpath('//*[@id="mG61Hd"]/div[2]/div/div[2]/div[1]/div/div/div[2]/div/div[1]/div/div[1]/input')
last.send_keys(Name)
Run Code Online (Sandbox Code Playgroud)
当我执行代码时,我收到一条错误消息,
AttributeError:“WebDriver”对象没有属性“find_element_by_xpath”
selenium browser-automation python-3.x selenium-chromedriver selenium-webdriver
在测试场景时,cucumber我在运行rspec测试时遇到以下错误
无法在60秒内获得稳定的firefox连接(127.0.0.1:7055)(Selenium :: WebDriver :: Error :: WebDriverError)
使用ruby (1.9.2) selenium-webdriver (2.27.2)和firefox (19.0)
使用rspec-rails (2.12.1),capybara (2.0.2)和其他几个宝石,我也添加了launchy宝石,但他们似乎没有问题.而我正在使用Windows 7.
ruby-on-rails cucumber capybara rspec-rails selenium-webdriver
我正在尝试使用scrapy从网页上抓取产品信息.我的待删节网页如下所示:
我试图复制next-button-ajax-call但是无法正常工作,所以我试试了selenium.我可以在一个单独的脚本中运行selenium的webdriver,但我不知道如何与scrapy集成.我应该把硒部分放在我的scrapy蜘蛛里?
我的蜘蛛非常标准,如下所示:
class ProductSpider(CrawlSpider):
name = "product_spider"
allowed_domains = ['example.com']
start_urls = ['http://example.com/shanghai']
rules = [
Rule(SgmlLinkExtractor(restrict_xpaths='//div[@id="productList"]//dl[@class="t2"]//dt'), callback='parse_product'),
]
def parse_product(self, response):
self.log("parsing product %s" %response.url, level=INFO)
hxs = HtmlXPathSelector(response)
# actual data follows
Run Code Online (Sandbox Code Playgroud)
任何想法都表示赞赏.谢谢!
我正在寻找类似于waitForElementPresent检查元素是否在我点击之前显示的东西.我认为这可以通过implicitWait,所以我使用以下内容:
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
Run Code Online (Sandbox Code Playgroud)
然后单击
driver.findElement(By.id(prop.getProperty(vName))).click();
Run Code Online (Sandbox Code Playgroud)
不幸的是,有时它等待元素,有时候不等.我找了一会儿找到了这个解决方案:
for (int second = 0;; second++) {
Thread.sleep(sleepTime);
if (second >= 10)
fail("timeout : " + vName);
try {
if (driver.findElement(By.id(prop.getProperty(vName)))
.isDisplayed())
break;
} catch (Exception e) {
writeToExcel("data.xls", e.toString(),
parameters.currentTestRow, 46);
}
}
driver.findElement(By.id(prop.getProperty(vName))).click();
Run Code Online (Sandbox Code Playgroud)
它等了很久,但在超时前它必须等待5次,50秒.有点多.所以我把隐式等待设置为1秒,直到现在一切都好了.因为现在有些事情在超时之前等待10秒,但是其他一些事情在1秒之后会超时.
您如何覆盖代码中存在/可见元素的等待?任何提示都很明显.
我试图在Debian 7上运行Selenium测试,但没有成功.
错误是:
unknown error: Chrome failed to start: exited abnormally (Driver info: chromedriver=2.9.248316,platform=Linux 3.2.0-4-686-pae x86) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 60.55 seconds Build info: version: '2.33.0', revision: '4ecaf82108b2a6cc6f006aae81961236eba93358', time: '2013-05-22 12:00:17' System info: os.name: 'Linux', os.arch: 'i386', os.version: '3.2.0-4-686-pae', java.version: '1.7.0_25' Driver info: org.openqa.selenium.chrome.ChromeDriver
Run Code Online (Sandbox Code Playgroud)
我有chromedriver 29,在Debian 7 32位上运行chrome 34.0.1847.76 beta.我使用的是selenium-java 2.33.0
在此链接之后,chromedriver 29是chrome 34的正确版本.无论如何,以前的版本因为glibc版本而无法在Debian 7上运行...
----------ChromeDriver v2.9 (2014-01-31)---------- …
selenium ×7
python ×4
webdriver ×4
java ×2
python-3.x ×2
c# ×1
capybara ×1
cucumber ×1
findelement ×1
new-window ×1
rspec-rails ×1
scrapy ×1
web-scraping ×1