webdriver

Native Events error trying to double-click element using watir-webdriver

a 夏天 提交于 2020-01-16 19:08:07
问题 I am writting automatic test for GWT application. And I try to double click on table element. I am using this code fo click: browser.element(:xpath, '/html/body/div[5]/div[2]/div/div/div/div[2]/div/div/div/div/div/div/div/div[2]/div/div[2]/div/div/table/tbody[2]/tr[1]/td[1]/div').double_click When this command is executed I get error like: test_search(TC_article_example):Selenium::WebDriver::Error::InvalidElementStateError: Cannot perform native interaction: Could not load native events

How to run TestNG suite from command line

自闭症网瘾萝莉.ら 提交于 2020-01-16 19:01:09
问题 I would like to run TestNG Suite from command line on Linux . I'm using eclipse to run test, but I have problem with command line. I know that I need to have testng.jar and I have it in /home/karcio/dev/testng-6.4.jar , location my suite xml is /home/karcio/git/java-test-automation/Automation/test-output/Default suite/TestSuite.xml . Commands what I tried, set classpath /home/karcio/dev/testng-6.4.jar cd /location to my suite xml file: java org.testing.TestNG TestSuite.xml This is error what

Selenium(七):截图显示等待

谁都会走 提交于 2020-01-16 15:23:36
一、显示等待(有条件等待) 常见问题: 定位明明是对的,为什么运行代码没找到定位。 定位明明是对的,找到定位了,文本信息为什么取到是空的? 分析原因: 没有处理frame 页面渲染速度比自动化测试的代码慢,页面还没渲染出来就定位了 异步请求,后端还未返回给前端,自动化测试代码就去获取页面文本数据 一些同学的解决解决方案: 加上time.sleep() 设置全局隐式等待,dr.implicitly_wait() 分析解决方案: 解决方案一,我们不能够确定准确的强制等待时间(代码休眠时间),导致自动化代码不稳定性大大增加,尤其是网络波动的影响,会导致页面加载速度变慢 全局等待虽可以解决一部分定位问题,例如需要定位的标签属性显现,但是如果像异步请求,需等待带有文本信息的相应,并渲染在页面上,不能确定在自动化代码执行获取文本信息的时候,页面已经渲染好所需要的文本信息 什么是显示等待? 条件满足后,不再等待 二、显示等待相关类 Wait.py class WebDriverWait(object): def __init__(self, driver, timeout, poll_frequency=POLL_FREQUENCY, ignored_exceptions=None): """构造函数,需要一个WebDriver实例并以秒为单位超时 :参数: - driver -

爬虫实战(三) 用Python爬取拉勾网

孤街醉人 提交于 2020-01-16 04:50:42
目录 0、前言 1、初始化 2、爬取数据 3、保存数据 4、数据可视化 5、大功告成 0、前言 最近,博主面临着选方向的困难(唉,选择困难症患者 >﹏<),所以希望了解一下目前不同岗位的就业前景 这时,就不妨写个小爬虫,爬取一下 拉勾网 的职位数据,并用图形化的方法展示出来,一目了然 整体的 思路 是采用 selenium 模拟浏览器的行为,具体的步骤如下: 初始化 爬取数据,这里分为两个部分:一是爬取网页数据,二是进行翻页操作 保存数据,将数据保存到文件中 数据可视化 整体的 代码结构 如下: class Lagou: # 初始化 def init(self): pass # 爬取网页数据 def parse_page(self): pass # 进行翻页操作 def turn_page(self): pass # 爬取数据,调用 parse_page 和 turn_page def crawl(self): pass # 保存数据,将数据保存到文件中 def save(self): pass # 数据可视化 def draw(self): pass if __name__ == '__main__': obj = Lagou() obj.init() obj.crawl() obj.save() obj.draw() 好,下面我们一起来看一下整个爬虫过程的详细分析吧!! 1

【WebDriver API】python之selenium多窗口切换

 ̄綄美尐妖づ 提交于 2020-01-16 04:10:23
在页面操作过程中有时候点击某个链接会弹出新的窗口,这时就需要主机切换到新打开的窗口上进行操作。WebDriver提供了switch_to.window()方法,可以实现在不同的窗口之间切换。 以百度首页和百度注册页为例,在两个窗口之间的切换。 多窗口切换1.py # coding=utf-8 from selenium import webdriver import time # 访问百度 driver = webdriver.Chrome() driver.get("http://www.baidu.com") # 获取百度搜索窗口句柄 search_windows = driver.current_window_handle driver.find_element_by_xpath('/html/body/div[1]/div[1]/div/div[3]/a[7]').click() time.sleep(3) driver.find_element_by_xpath('/html/body/div[4]/div[2]/div[2]/div/div/div/div/div/div[3]/a').click() # 获取打开所有窗口句柄 all_handles = driver.window_handles # 进入注册窗口 for handle in all_handles:

Including one method multiple times in a test in testng.xml to execute steps multiple times

99封情书 提交于 2020-01-15 19:12:58
问题 I want to execute a set of test methods multiple times as part of a test. I'm using TestNG to specify my tests. The test I have specified in the testng.xml file is this: <test> <classes> <class name="AddAppointment"> <methods> <include name="testLogin" /> <include name="addAppointment" /> <include name="checkApptForCurrentLocation" /> <include name="changeLocation" /> <include name="addAppointment" /> <include name="checkApptForCurrentLocation" /> </methods> </class> </classes> </test> After

Including one method multiple times in a test in testng.xml to execute steps multiple times

寵の児 提交于 2020-01-15 19:12:33
问题 I want to execute a set of test methods multiple times as part of a test. I'm using TestNG to specify my tests. The test I have specified in the testng.xml file is this: <test> <classes> <class name="AddAppointment"> <methods> <include name="testLogin" /> <include name="addAppointment" /> <include name="checkApptForCurrentLocation" /> <include name="changeLocation" /> <include name="addAppointment" /> <include name="checkApptForCurrentLocation" /> </methods> </class> </classes> </test> After

selenium 常见元素操作:三大等待

三世轮回 提交于 2020-01-15 13:33:12
selenium 常见元素操作 三大等待 三大切换(iframe,window,alert) 下拉列表 鼠标和键盘 js+ dom应用() 上传操作 强制等待:time.sleep() (译:私立破)   必须等待固定时间后才可以往下运行 from selenium import webdriver import time # 强制等待需要导入time,使用其中的sleep方法 # 强制等待 sleep(译:私立破) # 打开谷歌浏览器,建立会话。启动Chromedriver.exe 打开Chrome driver = webdriver.Chrome() # 访问百度首页 driver.get("http://www.baidu.com") # 点击登录按钮 driver.find_element_by_xpath('//div[@id="u1"]//a[@name="tj_login"]').click() # # 强制等待5秒,在进行下一步操作 time.sleep(10) # 点击 用户名登录 按钮 driver.find_element_by_id("TANGRAM__PSP_10__footerULoginBtn").click() # 强制等待5秒后关闭浏览器 time.sleep(10) driver.quit() 智能等待分为:隐形等待、显性等待 隐形等待

Selenium Webdriver: The method alert() is undefined for the type WebDriver.TargetLocator

你离开我真会死。 提交于 2020-01-15 11:59:06
问题 I am trying to handle alerts using Selenium Webdriver, according the selenium documentation the correct implementation is: Alert alert = driver.switchTo().alert(); However I am getting error message The method alert() is undefined for the type WebDriver.TargetLocator what version of Selenium 2 has this web driver api 回答1: I'm using selenium 2.3 and it works for me. From what I've seen, alerts only work with windows that ONLY have the ok button. Thats where you put the alert.accept();

mootools, watir webdriver onmouseover take no effect

淺唱寂寞╮ 提交于 2020-01-15 10:57:06
问题 My test shows that webdriver fire_event("onmouseover") takes no effect when page has mootools lib. when remove mootools lib, fire_event("onmouseover") takes effect. how can I get a workaround? html page is following: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <script type='text/javascript' src='http://demos111.mootools.net/demos/mootools.svn.js'></script></head> <body> <div onmouseover="document.getElementById('id6').style.display=