html tool

显示标签为“Selenium”的博文。显示所有博文
显示标签为“Selenium”的博文。显示所有博文

2017年9月21日星期四

Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases

问题: selenium + java 运行提示如下:
[selenium 3.5.3 + java 1.8.0]
"Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases"

参考:https://stackoverflow.com/questions/38676719/selenium-using-java-the-path-to-the-driver-executable-must-be-set-by-the-webdr



The Selenium client bindings will try to locate the geckodriver executable from the system PATH. You will need to add the directory containing the executable to the system path.
  • On Unix systems you can do the following to append it to your system’s search path, if you’re using a bash-compatible shell:
    export PATH=$PATH:/path/to/geckodriver
  • On Windows you need to update the Path system variable to add the full directory path to the executable. The principle is the same as on Unix.
All below configuration for launching latest firefox using any programming language binding is applicable for Selenium2 to enable Marionette explicitly. With Selenium 3.0 and later, you shouldn't need to do anything to use Marionette, as it's enabled by default.
To use Marionette in your tests you will need to update your desired capabilities to use it.
[popexizhi: 这里自己使用的是3.5.3应该不用下载才对,但看了不可以,不知道为什么,下载了一下,在下面代码中指定了一下就可以运行了,我本地最后用55.0firefox 才行, geckodriver-v0.19.0-win64 的 https://github.com/mozilla/geckodriver/releases
v0.19.0 支持如下:
  • Firefox 55.0 (and greater)
  • Selenium 3.5 (and greater)
]
Java :
As exception is clearly saying you need to download latest geckodriver.exe from here and set downloaded geckodriver.exe path where it's exists in your computer as system property with with variable webdriver.gecko.driver before initiating marionette driver and launching firefox as below :-
//if you didn't update the Path system variable to add the full directory path to the executable as above mentioned then doing this directly through code
System.setProperty("webdriver.gecko.driver", "path/to/geckodriver.exe");

//Now you can Initialize marionette driver to launch firefox
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new MarionetteDriver(capabilities); 
【popexizhi:
分别制定了geckodriver 和 firefox 的位置如下: 
public class ExampleForFireFox {
 public static void main(String[] args){
  System.setProperty("webdriver.gecko.driver", "G:\\w\\selenium\\geckodriver-v0.19.0-win64\\geckodriver.exe"); //
  System.setProperty("webdriver.firefox.bin", "D:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
  WebDriver driver = new FirefoxDriver();
  
  driver.get("http://192.168.1.88");
  System.out.println("title: " + driver.getTitle());
  
 }
 
 
}




2016年8月3日星期三

linux gui test II

add:https://stackoverflow.com/questions/22130109/cant-use-chrome-driver-for-selenium



For Linux

1. Check you have installed latest version of chrome brwoser-> "chromium-browser -version"
2. If not, install latest version of chrome "sudo apt-get install chromium-browser"
3. get appropriate version of chrome driver fromhttp://chromedriver.storage.googleapis.com/index.html
4. Unzip the chromedriver.zip
5. Move the file to /usr/bin directory sudo mv chromedriver /usr/bin
6. Goto /usr/bin directory and you would need to run something like "chmod a+x chromedriver" to mark it executable.
7. finally you can execute the code.

import os
from selenium import webdriver
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()
driver = webdriver.Chrome()
driver.get("http://www.google.com")
print driver.page_source.encode('utf-8')
driver.quit()
display.stop()

[popexizhi]
pyvirtualdisplay 依赖 xvfb 
pip install pyvirtualdisplay 前请sudo apt-get install xvfb
就可以直接使用了

2016年8月2日星期二

linux 虚拟机安装gui测试环境

问题:
通过ssh 在linux上测试chrome页面

解决方式:
安装Xvfb,指定使用DISPLAY运行
[最简单流程]
sudo apt-get install xvfb
sudo apt-get install xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic
Xvfb :99 -ac &
export DISPLAY=:99
google-chrome &
sudo apt-get install screen
screen

google-chrome setup in linux
sudo apt-get install libxss1 libappindicator1 libindicator7
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome*.deb
sudo apt-get install -f

参考:
http://stackoverflow.com/questions/7109840/cannot-start-browser-for-selenium-through-ssh
http://askubuntu.com/questions/79280/how-to-install-chrome-browser-properly-via-command-line
http://stackoverflow.com/questions/28392949/running-chromium-inside-docker-gtk-cannot-open-display-0
http://stackoverflow.com/questions/15929685/running-test-ng-selenium-tests-through-ssh/19236773#19236773

其他问题:
1.firefox运行时有碰到如下提示
Client failed to connect to the D-BUS daemon
但不影响测试

2.Xvfb :21 -screen 0 1024x768x24 +extension RANDR &

Cannot establish any listening sockets - Make sure an X server isn't already running(EE)

2015年6月2日星期二

css正则选择

参考地址:http://www.qianduan.net/taming-advanced-css-selectors/
----------------------------
有6个不同类型的属性选择器:
  • [att=value]
    该属性有指定的确切的值。
  • [att~=value]
    该属性的值必须是一系列用空格隔开的多个值,(比如,class=”title featured home”),而且这些值中的一个必须是指定的值”value”。
  • [att|=value]
    属性的值就是“value”或者以“value”开始并立即跟上一个“-”字符,也就是value-。(比如lang=”zh-cn”)
  • [att^=value]
    该属性的值以指定值开始。
  • [att$=value]
    该属性的值包含指定的值(而无论其位置)。
  • [att*=value]
    该属性的值以指定的值结束
比如,如果你想要改变你的博客上的日志部分元素的背景颜色,你可以使用一个指定每一个class属性值以“post-”开始的div的属性选择器:
div[class|="post"] { background-color: #333; }  

该语句将匹配所有class属性包含”post”并带”-“字符的div元素。(注:此处英文原文有些上下文不对应,我已经更正——译者,神飞)
-------------------------------------

2015年5月27日星期三

从iframe切换回主框架

/*功能说明
从iframe中切换回主框架
*/
Java 版本代码

         System.out.println(driver.getCurrentUrl()) //打印为iframe的url
this.driver.switchTo().defaultContent();//切换回主框架
System.out.println(driver.getCurrentUrl()) //打印为当前页面的url

python 版
         driver.switch_to.default_content()

2015年5月11日星期一

selenium windows窗口切换使用title,可以部分匹配

java版本
windows窗口切换使用title,可以部分匹配

/*add:http://blog.csdn.net/dongtianlaile/article/details/10176051
   *功能:对driver中全部的windows遍历,查找包含title中包含指定内容的,切换到相应窗口,并返回true;否则返回false
   *import java.util.Set; //set using
   */
  public boolean switchToWindow(WebDriver driver,String windowTitle){  
     boolean flag = false;  
     try {  
         String currentHandle = driver.getWindowHandle();  
         Set handles = driver.getWindowHandles();//getWindowHandles();  
         
         for (String s : handles) {  
             if (s.equals(currentHandle))  
                 continue;  
             else {  
                 driver.switchTo().window(s);  
                 System.out.println(driver.getTitle());
                 if (driver.getTitle().contains(windowTitle)) {  
                     flag = true;  
                     System.out.println("Switch to window: "  
                             + windowTitle + " successfully!");  
                     break;  
                 } else  
                     continue;  
             }  
         }  
     } catch (NoSuchWindowException e) {  
         System.out.println("Window: " + windowTitle
           + " cound not found!");  
         flag = false;  
     }  
     return flag;  
  }

selenium window switch

问题:多窗口切换,遍历窗口切换回最后的窗口内容
解决:
java版本
参考:http://blog.csdn.net/dongtianlaile/article/details/10176051

      //获取当前窗口 [popexizhi:保存切换前的handle 句柄]
      String winHandleBefore = driver.getWindowHandle();
      ... //other doing
      
 for (String handle : driver.getWindowHandles()) {
      System.out.println(handle);
      if (handle == winHandleBefore)
              continue; //旧窗口不操作
      else //只对新窗口操作 
       driver.switchTo().window(handle);
         
      }  

python版

add:http://www.cnblogs.com/Ralph-Wang/p/3393401.html

---------------------------------------
# 点击链接,打开新窗口
l = dr.find_element_by_xpath("//body/a")
l.click()
 
old_handle = dr.current_window_handle 
[popexizhi:保存旧的窗口句柄]
for handle in dr.window_handles:
    if old_handle != handle:
        new_handle = handle
        break

# 切换到新窗口中,点击新窗口中的按钮
dr.switch_to_window(new_handle)
btn = dr.find_element_by_xpath('//input[@id="b1"]')

selenium 双击事件

问题:页面操作中有双击效果的要求
解决:
Java版 参考:http://www.ifree168.com/lib/?p=5034

import org.openqa.selenium.interactions.Actions; //双击事件使用 [popexizhi:add]

...
          //[popexizhi]相关内容为双击操作
          Actions action = new Actions(driver); 
          action.doubleClick().perform();// 鼠标在当前停留的位置做双击操作 
          action.doubleClick(driver.findElement(By.xpath(".//*[@id='96']/td[2]"))).perform();// 鼠标双击指定的元素

Python版 参考:http://www.cnblogs.com/fnng/p/3288444.html
from selenium.webdriver.common.action_chains import ActionChains
#定位到要双击的元素
qqq =driver.find_element_by_xpath("xxx")
#对定位到的元素执行鼠标双击操作
ActionChains(driver).double_click(qqq).perform()

2015年5月10日星期日

selenium 页面选择内容动态加载问题

问题:参见下图的选择类别,定位时总是提示无法找到控件
解决:
使用css_selector定位
考虑到二级和三级菜单是动态出现的,加入隐式判断等待
java代码如下:

   private void _change_kind_seach_x() {
    String __doc__="添加科目--点击方式";
       oppor_Test.Message_print("start: "+__doc__);
       driver.findElement(By.cssSelector("div.wj.clearfix.wj_bg01>div>div>div>ul>li:nth-child(5)")).click();
       
       String sencond=".winScroll01.wj_width01.h294:nth-child(2)>div>ul>li:nth-child(2)";
       (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(sencond)));
       driver.findElement(By.cssSelector(sencond)).click();
       
       driver.findElement(By.cssSelector("div[style='padding: 0px; top: 0px;']>ul>li:nth-child(3)")).click();
       
       oppor_Test.Message_print("end: "+__doc__);
   }

python代码如下
 def change_kind_seach_x(self):
  """添加参数-选择商机类目(change click)"""
  print "start: change click"
  second_change_css=".winScroll01.wj_width01.h294:nth-child(2)>div>ul>li:nth-child(2)"
  driver = self.driver

         driver.find_element_by_css_selector("div.wj.clearfix.wj_bg01>div>div>div>ul>li:nth-child(5)").click()
  WebDriverWait(driver,10).until(EC.presence_of_element_located((By.CSS_SELECTOR,second_change_css)))
         driver.find_element_by_css_selector(second_change_css).click()
         driver.find_element_by_css_selector("div[style='padding: 0px; top: 0px;']>ul>li:nth-child(3)").click()

  print "end: "+self.change_kind_seach.__doc__
  print "*"*20

2015年5月6日星期三

selenium swf 处理 上传文件

问题:
上传文件使用的是flash按钮


参考:http://osdir.com/ml/selenium-users/2012-12/msg00657.html
You'd have to go with external tool like AutoIt or Sikuli.
[popexizhi]
看来selenium没有提供好的flash处理接口,上面提到的AutoIt我go了一下
参考:http://blog.csdn.net/kittyboy0001/article/details/25557147
是个“用来在Windows GUI(用户界面)中进行自动操作”,
ok,只能用这样的工具处理,我写了AHK的脚本,脚本如下:

#IfWinActive,打开 ;ahk_class #32770 ;切换到弹出的选择文件窗口
    WinActivate,打开 ;将窗口前置
    Send,c:\logo1.jpg ;输入文件地址
    Send,!+o ;打开文件操作
#IfWinActive

编译为exe进程在其他脚本中直接用了。

AHK相关资料:
http://blog.csdn.net/foxbryant/article/details/7605714
http://blog.csdn.net/foxbryant/article/details/7628392
要处理窗口的spy信息
>>>>>>>>>>( Window Title & Class )<<<<<<<<<<<
打开
ahk_class #32770

>>>>>>>>>>>>( Mouse Position )<<<<<<<<<<<<<
On Screen: 804, 643  (less often used)
In Active Window: 804, 599

>>>>>>>>>( Now Under Mouse Cursor )<<<<<<<<

Color: 0x000000  (Blue=00 Green=00 Red=00)

>>>>>>>>>>( Active Window Position )<<<<<<<<<<
left: 0     top: 44     width: 640     height: 512

>>>>>>>>>>>( Status Bar Text )<<<<<<<<<<

>>>>>>>>>>>( Visible Window Text )<<<<<<<<<<<
命名空间树控件
树视图
ShellView
文件名(&N):
文件类型(&T):
打开(&O)
取消
地址: 库\图片

>>>>>>>>>>>( Hidden Window Text )<<<<<<<<<<<
命名空间树控件
Shell Preview Extension Host
帮助(&H)

>>>>( TitleMatchMode=slow Visible Text )<<<<
*.jpg;*.jpeg;*.bmp;*.png;*.gif (*.jpg;*.jpeg;*.bmp;*.png;*.gif)

>>>>( TitleMatchMode=slow Hidden Text )<<<<



switchTo().frame 通过by_css

问题:要切换的frame没有name或者id

解决:使用嵌套的element定位就可以了
driver.switchTo().frame(driver.findElement(By.cssSelector("td.aui_main > div > iframe")));//切换tab的frame

参考:http://stackoverflow.com/questions/20069737/how-to-identify-and-switch-to-the-frame-in-selenium-webdriver-when-frame-does-no

2015年4月28日星期二

BDD_lettuce_before&after

参考地址:http://lettuce.it/reference/terrain.html

------------------------------------------------

@before.all

This hook is ran before lettuce look for and load feature files
The decorated function takes NO parameters
[popexizhi]这个没有参数的应该相对于其他的比较特殊吧!全部feature文件加载前.

@after.all

This hook is ran after lettuce run all features, scenarios and steps
The decorated function takes a TotalResult as parameter, so that you can use the result statistics somehow
from lettuce import *

@after.all
def say_goodbye(total):
    print "Congratulations, %d of %d scenarios passed!" % (
        total.scenarios_ran,
        total.scenarios_passed
    )
    print "Goodbye!
[popexizhi]这里的total应该是一个不错的出report的收集者,回头集成报告可以直接使用了。
---------------------------------------------------------------------------

@before.each_feature

@after.each_feature

[popexizhi]This hook is ran before/after lettuce run each feature
这里的要求参数是feature,下面例子是after的,这个可以看成测试用例集或测试suit吧!
from lettuce import *

@after.each_feature
def teardown_some_feature(feature):
    print "The feature %r just has just ran" % feature.name
-------------------------------------------------------------------------------

@before.each_scenario

@after.each_scenario

[popexizhi]This hook is ran before/after lettuce run each scenario.
感觉lettuce给了很充分的插槽处理位置,可以针对不同位置,一类位置的处理
from lettuce import *
from fixtures import populate_test_database

@before.each_scenario
def setup_some_scenario(scenario):
    populate_test_database()
-----------------------------------------------------------------------------------

@before.each_step

This hook is ran before lettuce run each step
The decorated function takes a Step as parameter, so that you can use it to fetch tables and so.

@after.each_step

This hooks behaves in the same way @before.each_step does, except by the fact that its ran after lettuce run the step.
from lettuce import *

@before.each_step
def setup_some_step(step):
    print "running step %r, defined at %s" % (
        step.sentence,
        step.defined_at.file
    )

[popexizhi] next看一下

django-specific hooks

Since lettuce officially supports Django, there are a few specific hooks that help on setting up your test suite on it.

@before.harvest

感觉lettuce的锚点定义好丰富啊,eg之后再来总结吧!





2015年4月7日星期二

css的not()选择器

find_elements_by_css_selector 定位

#pagelist>ul>li[name="page_unit"]>a:not(.current)
参考:
http://www.qianduan.net/taming-advanced-css-selectors.html
http://www.divcss5.com/css3/attribute_selector_18.html
[popexizhi]
看了这个才发现css的定位是和正则一样丰富的啊,从^,not()上看感觉都是同源语言,想到之前看过说jquery的sizzle 和xpath的关系看来有时间应该查查这个同源问题了:)
上面这个表达式有个遗留问题,就是不能对其中的每个元素单独调用js 这个问题起源于self.driver.find_element_by_css_selector(pagenum_css).click()使用时js冲突引起的效果与预期不一致,只用使用

pagenum_css_js='''$('#pagelist>ul>li[name="page_unit"]>a:not(.current)').click()'''
执行完成,所以还需进一步定位

等待添加位置 -selenium 中等待添加位置

问题:每次有菜单切换和页面切换后控件操作总是与页面加载不合拍而出现报错
解决:
其实还是使用隐式等待和显式等待来解决,但问题是这个等待的位置之前自己理解上一直有问题,应该把预期结果的位置写成等待位置,因为正是其实这个等待查询也是一个预期。
例如如下中菜单点击操作后,这个WebDriverWait 就是预期这个操作的打开效果的。之前理解不透彻,改进一下。对有操作后其实都有预期,只是这个预期有的是check的范围有的不是对testcase中只是前置条件和预期结果的区别,对代码中也有assert和WebDriverWait的区别吧!
----------------------源码的分割线-------------------------------
         
from selenium.webdriver.support.ui import Select,WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
 
......
                self.driver.find_element_by_link_text(u"销售中心").click()
  #判断菜单加载效果
  wait_css="html>body>div.wrapper.mt158.position>div#leftMenuParent.leftCont.row>div#left1.tree>ul#leftMemu0>li.tree-f.currS>p#menuId295"
                WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, wait_css)))

2015年3月2日星期一

selenium-java 库依赖

java中加载"selenium-server-standalone"
[问题]
eclipse 编译时提示“terminated exit value 0”
{详细内容如下:
d:\MyEclipse\Common\binary\com.sun.java.jdk.win32.x86_64_1.6.0.013\bin\javaw.exe (2015-3-3 上午10:06:10)
}
[解决]
加载jar包selenium-server-standalone-2.41.0.jar 后就没有这个问题了。但还是不解,我用的是WebDriver,不是rc啊?!

猜想是底层的其他库WebDriver中没有添加jar包吧?将lib中的jar报全部导入后果然就可以了。

ok,2.41. 2.43 存在测试此过程通过     

2015年3月1日星期日

jquery-iframe中tab切换无效果的解决过程log

jquery-iframe中tab切换无效果的解决过程log
[问题描述]产品页面的中的tab切换时,使用xpath定位点击click后没有触发点击效果反而出现了tab消失的情况,直接使用js调用后页面没有点击效果。
[原因]
1.点击click的效果是由于当前页面是iframe中的,被上层页面的遮盖了tab,click事件触发时出现问题,但why应该和selenium的鼠标事件驱动有关,暂时还没有查询到最终的原因
2.页面调用js:$("a[name='statusTab']:nth-child(3)").click() 没有执行效果,是因为这个页面中还有一个百度的js把全部的a.click事件都劫持了,这个是我的猜想因为在url中执行时其他事件都可以驱动,只有这个a的事件连jquery.js中的事件都无法进入,而单独执行javascript:$("a").click();void(0);在url中就会出现百度的分享插件,所以做此推测。但是没有实验验证。

url 执行的js命令:
add:http://www.douban.com/group/topic/21637079/
javascript:$("a[name='statusTab']:nth-child(3)").click();void(0);
javascript:$("dt>a[typeid="1"]>span").click();void(0);
[popexizhi: $("dt>a[typeid="1"]>span").click() 这个是ok的,脚本添加后测试也通过了,其中偶然测试了dt>a>span还有遍历全部控件执行的效果,惊奇一个. note!]

javascript:$("a").click();void(0);
javascript:$("#searchSpan").click();void(0);
javascript:$("a>span#searchSpan").click();void(0);
javascript:$("a[name='statusTab']:nth-child(1)").removeClass();void(0);
javascript:$("a[name='statusTab']").click();void(0);
javascript:$("a[class='edit msg_wbox5']").live("click");void(0);
javascript:$("a[name='statusTab']:nth-child(3)").live("click");void(0);
javascript:$("a[typeId='2']").live("click");void(0);

firebug命令行和搜索
搜索脚本:
默认帮助使用【类比vi】
! 搜索all files
@ 搜索函数定义
# 在文件中查找
: 跳转到指定行[vim相同]
* 过滤变量[try了一下,是对变量栏中的数据筛选用的]
other:阅读自带的工具[popexizhi:是不是这个想一个最低okrs啊?!作为内化的行为try?note thinking 一下]

命令行:
打印方式
console.log()这个就可以了,调试使用挺方便的
查找方式
[ps:chrome 的控制台可以指定Hide network messages, firebug和firefox的开发者工具都没发现有,对于html页面中加了状态连接的页面真心的方便好用。:)赞一个]
firefox和chrome开发者工具中的
:link  /* 未访问的标签 */
:visited  /* 已访问的标签 */
:hover  /* 鼠标在标签上 */
:active  /* 激活标签 */

[next]
css路径筛选器的使用
firebug中提供的firepath
{add:http://www.douapp.com/post/150158
FirePath 是Firebug的扩展插件,添加了开发工具,可以编辑,监测和生成XPath 1.0表达式,CSS 3选择符和JQuery的选择符}
这里多说一下Sizzle {add:http://blog.csdn.net/freshlover/article/details/10813657}
作为jquery1.3开始使用sizzle,Sizzle,作为一个独立全新的选择器引擎,出现在jQuery 1.3版本之后,并被John Resig作为一个开源的项目,可以用于其他框架:Mool, Dojo,YUI等。
[next]learning sizzle定位语法

2015年2月11日星期三

selenium 窗口切换python

add:http://www.cnblogs.com/Ralph-Wang/p/3393401.html

---------------------------------------
# 点击链接,打开新窗口
l = dr.find_element_by_xpath("//body/a")
l.click()

old_handle = dr.current_window_handle
[popexizhi:保存旧的窗口句柄]
for handle in dr.window_handles:
    if old_handle != handle:
        new_handle = handle
        break

# 切换到新窗口中,点击新窗口中的按钮
dr.switch_to_window(new_handle)
btn = dr.find_element_by_xpath('//input[@id="b1"]')
btn.click()

# 关闭alert
alert = dr.switch_to_alert()
alert.accept()

sleep(3)
dr.close()
# 切回到原页面关闭
dr.switch_to_window(old_handle)
[popexizhi:这里才是重要的,但使用时有切换不回来的情况,还是偶发的why??]
dr.close()


2015年2月5日星期四

selenium动态等待 presence_of_element_located

动态等待页面元素加载:
add:http://selenium-python.readthedocs.org/en/latest/waits.html

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Firefox()
driver.get("http://somedomain/url_that_delays_loading")
try:
    element = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.ID, "myDynamicElement"))
    )
finally:
    driver.quit()
This waits up to 10 seconds before throwing a TimeoutException or if it finds the element will return it in 0 - 10 seconds. WebDriverWait by default calls the ExpectedCondition every 500 milliseconds until it returns successfully. A successful return is for ExpectedCondition type is Boolean return true or not null return value for all other ExpectedCondition types.

[popexizhi]其中presence_of_element_located的首个参数应该都是大写要求吧?!
我修改的是是如下:WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.XPATH, _xpath)))

2014年11月30日星期日

selenium 网页富文本输入

问题描述:
网页富文本输入
html源码:
       * 产品说明:
       
             

                     
请从产品性能、用途、包装、售后服务等方面来描述。

                     
                     
                     

产品说明不能为空
             

...
...
...

2014年11月4日星期二

js for selenium 的例子python

python 源码
------------------------------------------------------------------------
    def test_alert(self):
        driver = self.driver
        driver.get(self.base_url + "file:///1-alert.html")
        driver.find_element_by_css_selector("button[value=\"alert\"]").click()
        #self.assertEqual(u"hi!", self.close_alert_and_get_its_text())
# 获得alert的焦点并处理
alert = driver.switch_to_alert()
print alert.text # alert 提示内容
alert.accept()

#getprompt
driver.find_element_by_css_selector("body > button").click()
alert = driver.switch_to_alert()
alert.send_keys("im here")
print alert.text #提示内容
alert.accept()
#print alert.text

#confirm
driver.find_element_by_xpath("//button[@onclick='myFunction_confirm()']").click()
alert =  driver.switch_to_alert()
print alert.text
alert.accept()

driver.find_element_by_xpath("//button[@onclick='myFunction_confirm()']").click()
alert =  driver.switch_to_alert()
print alert.text
alert.dismiss()
print driver.find_element_by_xpath("//p[@id='demo2']").text

------------------------------------------------------------------------
js 源码
------------------------------------------------------------------------



 


 Click the button to demonstrate the prompt box.







Click the button to display a confirm box.







----------------------参考-----------------------------
js:
http://www.w3schools.com/jsref/met_win_prompt.asp
http://www.w3schools.com/jsref/met_win_confirm.asp
python selenium API
http://selenium-python.readthedocs.org/en/latest/api.html