Selenium issues met during practice

1. disabled button

in selenium 1.0,

Inspect the javascript on the page to see how the button is enabled upon typing. It's most likely through an event listener on a keyUp event or something similar on the given field. In that case, you can either use typeKeys instead of type or you can fire the relevant event when you finished typing using fireEvent method.

fire_event ( locator, eventName ) [source]

Explicitly simulate an event, to trigger the corresponding “onevent”handler.

‘locator’ is an element locator‘eventName’ is the event name, e.g. “focus” or “blur”

type_keys ( locator, value ) [source]

Simulates keystroke events on the specified element, as though you typed the value key-by-key.

This is a convenience method for calling keyDown, keyUp, keyPress for every character in the specified string;this is useful for dynamic UI widgets (like auto-completing combo boxes) that require explicit key events.

Unlike the simple “type” command, which forces the specified value into the page directly, this commandmay or may not have any visible effect, even in cases where typing keys would normally have a visible effect.For example, if you use “typeKeys” on a form element, you may or may not see the results of what you typed inthe field.

In some cases, you may need to use the simple “type” command to set the value of the field and then the “typeKeys” command tosend the keystroke events corresponding to what you just typed.

‘locator’ is an element locator‘value’ is the value to type


2. java scipt - drop down list

soluction 1:
(JavascriptExecutor(webdriver)).executeScript("document.getElementsByClassName('post-tag')[0].click();");
soluction 2:

webdriver.backendselenium.


3. dynamica element

Solution: try to locate it with the unchanged html tags if there is .

Solution 2: using regex.

4. multiple windows to focus


5.hidden menu ,link, submenu

  • How to click on a hidden link in WebDriver?
  • ow to click on a hidden element in WebDriver?
  • How to click on a SubMenu which is only visible after hovering the mover over to Menu?

Environment:
OS : Windows 7 / Browser: IE9 and FF10 / Web Driver : Selenium 2.19.0

Issue:

In Selenium WebDriver, I found one issue that was about the link in the Sub Menu that I wanted to do check and then click. Now, The main Menu was fixed on the page so that I could click on that element and got the text and confirmed. However, while trying to get the value for a SubMenu, I failed. It did not find those element and I found that there is the problem.

Solution:

WebDriver actually emulates user actions so it will only be able to do those things that a user is able to do. In the webpage that I was testing, it uses a JavaScript to load the Menu and then while hovering my mouse over to that Menu Text it loaded the SubMenu. So that means to say, at page load the SubMenu was hidden.

Now, to get a work around this issue, I had to first move my mouse towards the main Menu (or click on it) to be able to display the SubMenu. There is not simple and straight answer to this issues. And ofcourse, then I googled it. I finally got to the answer of using Actions in the code. Here is the code if you want to have a look at it.

  1. WebElement mnuElement;  
  2. WebElement submnuElement;  
  3. mnEle = driver.findElement(By.Id("mnEle")).Click();  
  4. sbEle = driver.findElement(By.Id("sbEle")).Click();  
  5.   
  6. Actions builder = new Actions(driver);  
  7. // Move cursor to the Main Menu Element  
  8. builder.MoveToElement(mnEle).Perform();  
  9. // Giving 5 Secs for submenu to be displayed  
  10. Thread.sleep(5000L);  
  11. // Clicking on the Hidden SubMenu  
  12. driver.findElement(By.Id("sbEle")).Click();  

The only problem with this code is it works like a charm with FF but doesn’t work with IE. In IE, mouse cursor does not stay on element and as a result popup becomes visible for a fraction of a second or doesn’t appear.

You can also use JQuery as another work around to this hence it will execute it and move the pointer as you need.
Using the .mouseover() method

  1. js.ExecuteScript("return $(\"a:contains('Fruits')\").mouseover();"); // Mouse hove to main menu  
  2. webDriver.FindElement(By.LinkText("Banana")).Click();  

 

OR using the .hover() method

  1. ((JavascriptExecutor)driver).executeScript("$('div#Fruits').hover();");  
  2. webDriver.FindElement(By.LinkText("Banana")).Click();  

 

OR using the .mouseenter() method

  1. ((JavascriptExecutor)driver).executeScript("$('div#Fruits').mouseenter();")  
  2. webDriver.FindElement(By.LinkText("Banana")).Click();

6.unable to locate element,

Solution 1: try to wait

Solution 2 : first, try to switch to the frame/iframe ,then try to locate the element. NOTE :Do NOT use frame id ,cause it may change dynamically!

(python code)

        
        time.sleep(10)
        frames = driver.find_elements_by_xpath('//iframe')
        for f in frames:
            print "iframe: ", repr(f)
        frames = driver.find_elements_by_xpath('//frame')
        for f in frames:
            print "frame: ", repr(f)

        frame = driver.find_element_by_xpath('//iframe[contains(@title, "Create News dialog")]')
        time.sleep(5)        
        driver.switch_to_frame(frame)

        time.sleep(5)
        elem = driver.find_element_by_id('edit-title')

        elem.send_keys('new1')

Solution 3. record the action on the element on selenium IDE ,then convert it to the required script format.

7. changin ID

Solution 1: try to use CSS-selector/Xpath (Note: Xpath maybe not be working on FireFox, and it's a slower location strategies)


8. dynamica constructed page


1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值