Appium+python Automation 98-Non Select pop-up selection box fix

Source: Internet
Author: User

Objective

Problems encountered: Document.getelementsbyclassname (...) [0] is undefined
Select box if it is a select tag, you can directly use the Select-specific method to locate the click operation. If the other is not the Select box, then follow the normal steps to enter the box first, then click on the option.
However, some choice box is not obedient, you will find that with selenium dead or alive to locate, this time can only use the universal JS to solve.

Input Selection box

1. First look at the pop-up box common, the following

2. View element properties, is the input tag, and is the ReadOnly property, stating that cannot be entered

JS debugging

1. First tried the selenium positioning method, found that the point input box can be pop-up options, but the point option is dead or alive. So in the browser with JS to debug

First click the input box, let it pop up the option

元素属性<input class="el-input__inner" type="text" autocomplete="off" placeholder="请选择" readonly="readonly">

Document.getelementsbyclassname (' El-input__inner ') [2].click ();

2. Other options pop out, again in the browser input JS go point option

元素属性<ul class="el-scrollbar__view el-select-dropdown__list" style="position: relative;">    <li class="el-select-dropdown__item hover">        <span>车赢银行</span>

Document.getelementsbyclassname (' hover ') [0].click ();

3. Then use selenium to execute JS, part of the reference code is as follows

js1 = "document.getElementsByClassName('el-input__inner')[2].click();"self.driver.execute_script(js1)time.sleep(1)js2 = "document.getElementsByClassName('hover')[0].click();"self.driver.execute_script(js2)

Operation Error:

Selenium.common.exceptions.WebDriverException:Message:document.getElementsByClassName (...) [0] is undefined

See this error after repeated check the grammar, found no problem, and repeatedly in the browser debugging, also no problems, almost suspect life!!! Later found that the previous JS execution lost focus, resulting in a second JS can not find the focus

Move mouse

1. When the element loses focus, after the death can not locate, this is like you in the browser to browse the small movie, suddenly there is a person sent to QQ jitter window, you want to continue to browse the small site, you need to re-click the page, so that the mouse can be clustered on the page to operate.
Workaround: Move the mouse back over

2. Using Actionchains to move the mouse to the element that needs to be clicked, refer to the code

from selenium import webdriverfrom selenium.webdriver.common.action_chains import ActionChainsimport time# ** 上海-悠悠 QQ交流群:588402570**driver=webdriver.Firefox()# 省略中间步骤js1 = "document.getElementsByClassName('el-input__inner')[2].click();"self.driver.execute_script(js1)time.sleep(1)el = driver.find_element_by_xpath("//*[text()='车赢银行']")ActionChains(self.driver).move_to_element(el).perform()js2 = "document.getElementsByClassName('hover')[0].click();"self.driver.execute_script(js2)

SELENIUMQQ Group: 646645429

Appium+python Automation 98-Non Select pop-up selection box fix

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.