Record the click problem of the select box in automatic test
1. Paste the code first
#Open the Google Chrome
driver=webdriver.Chrome();
#driver.fullscreen_window();
#input the Google
driver.get('https://www.google.com/');
#driver.find_element_by_xpath("//*[@id='tsf']/div[2]/div[1]/div[1]/div/div[2]/input").send_keys('新冠状病毒');
time.sleep(1);
#Click the I'm feel Luckly
driver.find_element_by_css_selector("#tsf > div:nth-child(2) > div.A8SBwf > div.FPdoLc.tfB0Bf > center > input.RNmpXc").click();
time.sleep(1);
# click about us
driver.find_element_by_css_selector("#nav-list > li:nth-child(2) > a").click();
time.sleep(1);
#Cyclic click on select checkbox
for index in range(len(driver.find_elements_by_tag_name("option"))):
driver.refresh();
select = driver.find_element_by_id("lang-chooser");
select_value = select.find_elements_by_tag_name("option");
time.sleep(2);
select_value[index].click();
time.sleep(2);
First, by_ tag_ The name method gets the option information in the select box, which is returned in the form of list
driver.find_elements_by_tag_name("option")
Then use the for loop to traverse the list of select options through the index number, and remove the current option of click ()
because each click on the select option will refresh the whole web page, an error will be reported
element is not attached to the page document
So we need to use it driver.refresh() method to refresh the current page, and then get the elements of the select option box again to click
Read More:
- The prefix “mvc” for element “mvc:view-controller” is not bound
- C# implementation of TXT document to table example code
- [Solved] Readiness probe failed: calico/node is not ready: BIRD is not ready: Error querying BIRD: unable to
- How to Solve Unzip Error: tar: Error is not recoverable: exiting now
- [Solved] check_urdf demo05_test.urdf Error: Error document empty. at line 71 in /build/urdfdom-YM
- Vue implements page caching with keep alive
- Debug record 2: debug error in ec20cehg Linux [How to Solve]
- [Solved] ERROR: The kernel module failed to load, because it was not signed by a key that is trusted by the
- [Solved] websocket: the client is not using the websocket protocol: ‘upgrade’ token not found in ‘Connection’ head
- [Solved] Snap Error: snap-confine has elevated permissions and is not confined but should be. Refusing to continue
- [Solved] Decompression error: tar: Error is not recoverable: exiting now
- hb set Error: OHOS ERROR] Invalid vendor path: /home/openharmony/vendor (openharmony Compile ubuntu20.04 official document)
- [Solved] Nginx cannot access pictures on FTP Error: Whitelabel error page
- [Solved] zookeeper Cluster error: Error: JAVA_HOME is not set and java could not be found in PATH.
- [Solved] tar (child): bzip2: Cannot exec: No such file or directory tar (child): Error is not recoverable: ex
- Git Syntax Error: TypeError: this.getOptions is not a function [How to Solve]
- How to Fix xterm Xt error: Can’t open display: xterm: DISPLAY is not set
- After Centos installation is complete, ifconfig: command not found
- error: ‘integer_sequence’ is not a member of ‘std’ [How to Solve]
- RuntimeError: 0:1 (10): error: GLSL 3.30 is not supported. [How to Solve]