Я новичок в изучении селена с python.
Постановка проблемы: -
Получение следующей ошибки при попытке идентифицировать объект в браузере chrome.
AttributeError: у объекта 'str' нет атрибут 'find_element'
Я понимаю, что переменная класса объявляется как строка, и назначенный веб-элемент не ссылается, когда я вызываю переменную класса "драйвер" из класса seleniumConfig.py, но не знаю, как чтобы исправить эту фундаментальную проблему. Любая помощь будет принята с благодарностью.
Примечание. Браузер запускается и URL-адрес корректно применяется, но проблема возникает, когда я хочу щелкнуть объект на странице.
Robot Framework : -
*** Settings ***
Resource /foo/boo/selenium_Keywords.robot
SampletestRun
[Documentation] To validate
[Tags] samplerun
Launching Browser
Login
selenium_Keywords.robot
*** Settings ***
Library /foo/boo/SeleniumConfig.py
Library /foo/boo/Pratice.py
*** Keywords ***
Launching Browser
browser
url
Login
click_button
SeleniumConfig.Py
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
class SeleniumConfig():
driver=""
def __init__(self):
self.driverPath="foo\boo\chrome.exe"
def browser():
SeleniumConfig.driver = webdriver.Chrome(self.driverPath)
def url():
SeleniumConfig.driver.get("www.google.com")
def get_driver()
return SeleniumConfig.driver
Selenium.py
from foo.boo.SeleniumConfig import SeleniumConfig
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.action_chains import ActionChains
class Selenium():
driver=SeleniumConfig()
def __init__(self):
self.driver = Selenium.driver.get_driver()
def click_object(webelement):
element = WebDriverWait(self.driver, 10).until(
EC.visibility_of_element_located((By.ID, webelement)))
ActionChains(self.driver).move_to_element(element).click(element).perform()
Practice.py
from foo.boo.Selenium import Selenium
class Practice():
sm=Selenium()
def click_button(self):
Practice.sm.click_object("webElement")
Результаты трассировки: -
SampletestRun :: To validate | FAIL |
AttributeError: 'str' object has no attribute 'find_element'