The origin of the problem: I am currently doing an internship in the company. Since the department needs to build an automated testing framework, I plan to use python to build a framework.
1. First, as shown in Figure 1, driver.find_element_by_tag_name('iframe') is marked yellow and reports an error.
2. Even if it is officially implemented, the browser is opened normally, but an error is reported when locating the element, prompting: AttributeError: 'WebDriver' object has no attribute 'find_element_by_id' this problem
My selenium version is 4.10.0. According to the online prompt, install the previous version, and then install the old version
####The new version reports an error, install selenium==3.141.0
Although there is no yellow mark, it cannot run at this time, and the error is as follows:
The display path problem is because the old version of selenium needs to read the path and cannot be resolved
In fact, the new version can be solved by referencing a package
from selenium.webdriver.common.by import By
Rewrite the previous code in the format of find_element_by_tag_name and it will be ok. The code is as follows:
import time
from selenium import webdriver
from Utils.fin_ele import find_element
from selenium.webdriver.common.by import By
#####WebUI自动化测试 PO模式
driver = webdriver.Chrome()
driver.get('https://mail.163.com/')
i_frame = driver.find_element(by=By.TAG_NAME, value='iframe')
driver.switch_to.frame(i_frame)
find_element(driver,'name','email').send_keys('my_username')
find_element(driver,'name','password').send_keys('my_password')
find_element(driver,'id','dologin').click()
time.sleep(10)
Paste By's code
ID = "id"
XPATH = "xpath"
LINK_TEXT = "link text"
PARTIAL_LINK_TEXT = "partial link text"
NAME = "name"
TAG_NAME = "tag name"
CLASS_NAME = "class name"
CSS_SELECTOR = "css selector"
There are a total of these 8 types that can be called. Of course, you can also try other methods, you can share them in the comment area