顯示具有 selenium 標籤的文章。 顯示所有文章
顯示具有 selenium 標籤的文章。 顯示所有文章

2015年10月5日 星期一

selenium

selenium get url of webpage
selenium2library 可以使用 keyword "Get Location"

另外Get Element Attribute 需要使用id name@class而非一般XPATH格式否則會有錯誤

The expression is not a legal expression

而使用Get Value獲取@href不行因為結果會是attribute而非element,會有錯誤

[object XrayWrapper [object Attr]]

當需要驗證popup windows兩者標題又相同無法switch window時,後來採取抓取button href資訊並直接go to就可以不被popup限制

參考資料
自己
http://stackoverflow.com/questions/15985339/how-do-i-get-current-url-in-selenium-webdriver-2-python

2015年2月3日 星期二

selenium download file, php

Download File [Arguments] ${COOKIE} ${URL} ${FILENAME} ${COOKIE_VALUE} = Call Selenium API get_cookie_by_name ${COOKIE} Run and Return RC wget --cookies=on --header "Cookie: ${COOKIE}=${COOKIE_VALUE}" -O ${OUTPUT_DIR}${/}${FILENAME} ${URL}

php POST變數.$_POST["item"]後方如果要接字必須以 "," or "." 隔開,否則會出錯

fopen file時在linux下會有權限問題,要注意需給予使用者read權限否則會無法讀取。

使用fgets取得txt資料時,會帶出行尾的特殊符號,以windows為例為\r\n。因此在做比對時,不論是使用==或strcmp()函數都需要先將這些特殊符號消去(或是在輸入端增加),才能成功比對。

我是使用ereg_replace("\r\n","",變數)來做。供參考。順帶一提,如果將\0消去則整個字串會消失。

想要驗證則可以使用strlen()函數來觀察字串的長度,就可以知道其實有特殊符號的存在。

最後apache的預設使用者是www-data(可去/etc/apache2/envvar修改),如果要使用fopen讀取檔案記得將www-data加到owner群組內,virtualbox shared folder共用資料夾則是要將www-data加到vboxsf群組內才可正常讀取。

#sudo gpasswd -a www-data vboxsf

#sudo usermod -G vboxsf www-data 有一樣效果

以下code可以查看group內成員
$ sudo grep ^群組名稱: /etc/group

過程中由於出錯使得apache內的log資料量暴增,一開始不知道只覺得硬碟空間怎麼消失這麼快,後來使用指令列出資料夾大小才找出來。max-depth是指只顯示一層,-B M是以MB表示,sort -g是照大小排列。

du -B M --max-depth=1 | sort -g

參考資料
自己經驗
https://blog.codecentric.de/en/2010/07/file-downloads-with-selenium-mission-impossible/
http://php.net/manual/en/function.shell-exec.php
http://stackoverflow.com/questions/2404794/strcmp-on-a-line-read-with-fgets
將ubuntu內資料夾所佔空間列出
http://banco.pixnet.net/blog/post/21967119-%5Bubuntu%5D-%E5%88%A9%E7%94%A8du%E6%90%AD%E9%85%8Dsort%E4%BE%86%E6%9F%A5%E7%9C%8B%E7%A3%81%E7%A2%9F%E4%BD%BF%E7%94%A8%E7%A9%BA%E9%96%93
fget
http://qaautomationworld.blogspot.in/2014/02/file-downlaoding-using-selenium.html
http://stackoverflow.com/questions/7618155/how-to-duplicate-a-request-using-wget-or-curl-with-raw-headers
https://addons.mozilla.org/zh-TW/firefox/addon/export-cookies/
http://stackoverflow.com/questions/4272770/wget-with-authentication

2014年11月26日 星期三

robotframework selenium2library

使用robotframework selenium時遇到兩個問題,第一個是使用cron設定排程時pybot無法啟動,後來看了一下應該是PATH的問題,後來使用原始執行緒python -m robot.run取代pybot後解決。第二個問題是browser無法啟動,會顯示Chrome failed to start: exited abnormally。後來找到解決方法是在shell script前面加一行export DISPLAY=:0即可正常執行。

參考資料
setup chromedriver
http://installselenium.blogspot.tw/2013/06/how-to-setupinstall-selenium.html
export DISPLAY=:0
http://stackoverflow.com/questions/6971595/how-to-set-a-cron-job-to-open-a-web-page-in-the-browser-using-crontab
http://stackoverflow.com/questions/23908319/run-selenium-with-crontab-python
python -m robot.run
自己

2014年8月20日 星期三

selenium 無法在背景執行問題

執行selenium測試時遇到一個問題就是一定要在桌面執行而無法在背景執行,造成很大困擾,因為必須保持桌面登入。後來研究了一下想到可能跟權限有關(經測試在桌面的terminal執行可以,ssh連入執行不可),同事研究了一下發現的確是,進入VNC更改使用者即可解決。

參考資料
同事