小编Exp*_*ode的帖子

设置selenium以使用自定义配置文件,但它会默认打开

我正在尝试使用python和selenium来自动执行firefox中的一些任务.当我下载文件时,弹出窗口询问您是否要打开或保存,以及每次使用此类文件执行此操作的复选框.我发现除非您在网页修复工具上安装添加,否则复选框不起作用.我有正常安装,但当我使用python + selenium时,它使用没有添加的配置文件.

互联网已指示我通过关闭Firefox,打开/ Applications/Utilities,然后键入命令来创建另一个配置文件:

/Applications/Firefox.app/Contents/MacOS/firefox-bin -p
Run Code Online (Sandbox Code Playgroud)

然后我创建一个新的配置文件,我将使用selenium.我设置名称并更改文件夹名称.配置文件名称为"PTI_Auto_Profile".文件夹路径显示如下:

/users/User/Library/Application Support/Firefox/Profiles/Selenium/
Run Code Online (Sandbox Code Playgroud)

当我完成.我点击"启动Firefox",终端屏幕上出现以下错误.

2013-04-11 11:57:30.422 firefox-bin[2248:707] invalid drawable
conf-room:~ User$ 2013-04-11 11:58:00.350 firefox-bin[2251:303] invalid drawable
Run Code Online (Sandbox Code Playgroud)

我试过以下没有成功.

profile = webdriver.FirefoxProfile(os.path.expanduser("~/Library/Application Support/Firefox/Profiles/Selenium/"))
driver = webdriver.Firefox(firefox_profile=profile) 
Run Code Online (Sandbox Code Playgroud)

没有错误,默认用户.

profile = webdriver.FirefoxProfile(os.path.expanduser("~/Library/Application Support/Firefox/Profiles/Selenium/"))
driver = webdriver.Firefox(profile) 
Run Code Online (Sandbox Code Playgroud)

没有错误,默认用户.

fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList",2)
fp.set_preference("browser.download.manager.showWhenStarting",False)
fp.set_preference("browser.download.dir",getcwd())
fp.set_preference("browser.helperApps.neverAsk.saveToDisk","text/csv/xls")

driver = webdriver.Firefox(firefox_profile=fp)
Run Code Online (Sandbox Code Playgroud)

错误:fp.set_preference("browser.download.dir",getcwd())NameError:名称'getcwd'未定义

关于我做错了什么的任何想法?谢谢!

ps我使用的是mac os x 10.8.2,python 2.7,firefox 20

Corey Goldberg提供的解决方案.这适用于所有excel版本.

import os
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2)
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.download.dir', os.getcwd())
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', ('application/vnd.ms-excel'))
driver = …
Run Code Online (Sandbox Code Playgroud)

python macos firefox selenium-webdriver

29
推荐指数
3
解决办法
4万
查看次数

Chromedriver:如何禁用Google Chrome浏览器帮助器

我在Mac上运行10个chromedriver浏览器,每个浏览器都使用1个标签,但是以某种方式产生了98个Google Chrome浏览器帮助程序。这些助手正在消耗我的可用内存,并严重限制了我可以在其上运行这些测试的硬件。

互联网似乎已经达成共识,可以通过转到/ settings / content settings / plugins,然后选择“点击播放”选项来禁用google chrome helper。

However, that option does not appear to exist in the current version of chrome. Instead the three options are:

Run all plugin content 
Detect and run important plugin content
Let me choose when to run plugin content (which is assume is the equivalent)
Run Code Online (Sandbox Code Playgroud)

To attempt to get the latter option as my default setting I created a blank folder, then ran this in the terminal

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --user-data-dir=/Users/User/Documents/Python/chome_helper_blank_folder …
Run Code Online (Sandbox Code Playgroud)

python macos selenium-chromedriver selenium-webdriver

6
推荐指数
0
解决办法
1696
查看次数

无法使用Homebrew with Mac 10.8.5完全卸载MYSQL如何从旧安装中查找/删除"/etc/my.cnf"?

这是我终端的样本.

My-MacBook-Pro:~ My$ brew update
Already up-tåo-date.
My-MacBook-Pro:~ My$ brew uninstall mysql
Error: No such keg: /usr/local/Cellar/mysql
My-MacBook-Pro:~ My$ brew install mysql
Warning: Your Xcode (4.5.2) is outdated
Please install Xcode 4.6.3.
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/mysql-5.6.1
Already downloaded: /Library/Caches/Homebrew/mysql-5.6.13.mountain_lion.bottle.tar.gz
==> Pouring mysql-5.6.13.mountain_lion.bottle.tar.gz
==> Caveats
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

To connect:
    mysql -uroot

To have launchd start mysql at login:
    ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
Then to load mysql now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist …
Run Code Online (Sandbox Code Playgroud)

mysql macos terminal homebrew

4
推荐指数
1
解决办法
1万
查看次数

即使元素存在,WebdriverWait也会失败

这是我的代码:

def CheckQueue(driver):
    qdone = False
    qID_xpath_start = "/html/body/div[5]/form/table/tbody[1]/tr["
    qID_xpath_end = "]/td[2]/a"
    qIDindex = 1
    while qdone == False:
        print "enter loop"
        print driver.find_element_by_xpath(qID_xpath_start+str(qIDindex)+qID_xpath_end).text #This prints
        try:
            element = WebDriverWait(driver, 6000).until(ec.presence_of_element_located(By.XPATH((qID_xpath_start+str(qIDindex)+qID_xpath_end)))) #This fails
            print "found"
        except:
            qdone= True
            print "could not be found"

        print driver.find_element_by_xpath(qID_xpath_start+str(qIDindex)+qID_xpath_end).text
        if qdone == False:
            print driver.find_element_by_xpath(qID_xpath_start+str(qIDindex)+qID_xpath_end).text
            print "testing"

        qIDindex +=1
        print "loop"
    return driver
Run Code Online (Sandbox Code Playgroud)

我得到这个返回(14453是我正在寻找的xpath的链接文本)

enter loop
14453
could not be found
14453
loop
Run Code Online (Sandbox Code Playgroud)

看来我的代码能够找到链接,但是当被要求检查链接是否存在时,它会失败,并激活except语句.如果已经找到并打印出来,它为什么会失败?

此外,它几乎立即失败,即使我已经分配了这么多时间来看.

知道我哪里错了吗?

我试过了

element = WebDriverWait(driver, 6000).until(ec.presence_of_element_located(By.XPATH((qID_xpath_start+str(qIDindex)+qID_xpath_end))))

element = WebDriverWait(driver, …
Run Code Online (Sandbox Code Playgroud)

html python selenium xpath selenium-webdriver

3
推荐指数
1
解决办法
1万
查看次数

我的导航列表是重叠填充.我怎么能阻止这个?

当您将鼠标悬停在链接上时,我正在尝试创建一个突出显示链接周围区域的导航,并允许您单击突出显示的任何区域以关注该链接.看起来我的填充是重叠的,你只能点击链接左边的填充,而右边的填充变成右边链接的左边距.

JSFiddle:http://jsfiddle.net/Hh7XG/1/

HTML

<div id="menubar">
      <ul>
        <li><a href=# >Home</a></li>
        <li><a href=# >About Us</a></li>
        <li><a href=# >Online Courses</a></li>
        <li><a href=# >Registration</a></li>
        <li><a href=# >Faculty</a></li>
        <li><a href=# >Calendar</a></li>
        <li><a href=# >Store</a></li>
        <li><a href=# >Testimonials</a></li>
        <li><a href=# >Online Lectures</a></li>
        <li><a href=# >Contact Us</a></li>
        <li><a href=# >Forum</a></li>
        <li><input class="searchbox" trype="text" value="Search" onfocus="this.value='';" onblur="if(this.value=='') this.value='Search';"/> </li>
      </ul>
    <div style="clear:both;"></div>
    </div>
Run Code Online (Sandbox Code Playgroud)

CSS

#menubar{
height:auto;
background:#ebebec;
margin-top:0px;
padding-top:0px;
padding-left:0px;
}
ul{
list-style-type:none;
padding:0px;
margin:0px;
}
#menubar ul li{
text-decoration:none;
color:#005da4;
text-align:center;
margin:none;
width:auto;
padding-left:0; …
Run Code Online (Sandbox Code Playgroud)

css padding overlap html-lists

2
推荐指数
1
解决办法
5715
查看次数

为什么我不能用selenium"send_keys"到文本框?AttributeError:'NoneType'

我在填写本网站的文本框时遇到了严重困难.元素是type ="text".它继续作为AttributeError返回:'NoneType'.

我使用了一个try子句来查看它是否实际被点击,并且它没有错误.此外,选择了文本框,当我将其保留为前窗时,我可以在发生错误后键入文本框而不单击任何内容.

我尝试将点击之前的暂停延长1分钟无效.

我尝试通过xpath选择,结果相同.

我尝试单击该对象,暂停10秒,然后再次单击该对象.没有.

我的代码:

def Search(driver,productID):
    print "Initiate Search"

    #Fill in current product ID
    #/html/body/table[3]/tbody/tr/td/table/tbody/tr/td[2]/div[2]/form/table/tbody/tr/td/input

    try: inputElement = driver.find_element_by_name("CategoryName").click()
    except: print "could not click"
    print "Clicked Product ID"

    time.sleep(5)
    inputElement.send_keys(str(productID))  ##Line 105 - Errors out here
Run Code Online (Sandbox Code Playgroud)

错误

Traceback (most recent call last):
  File "/Users/ME/Documents/PYTHON/Creating Static Attributes/StaticWAttributes_1.py", line 246, in <module>
    Search(driver,productID)
  File "/Users/ME/Documents/PYTHON/Creating Static Attributes/StaticWAttributes_1.py", line 105, in Search
    inputElement.send_keys(str(productID))
  AttributeError: 'NoneType' object has no attribute 'send_keys'
Run Code Online (Sandbox Code Playgroud)

最后输出打印声明:

Initiate Search
Clicked Product ID
Run Code Online (Sandbox Code Playgroud)

HTML:

  <table cellSpacing="0" cellPadding="0" …
Run Code Online (Sandbox Code Playgroud)

python selenium nonetype

1
推荐指数
1
解决办法
1万
查看次数