Iam working on the robotframework, i want to highlight the element on the page below is the code i am getting the error
"AttributeError: 'str' object has no attribute '_parent' "
Below is the code,
import time
def highlight(element):
"""Highlights (blinks) a Selenium Webdriver element"""
driver = element._parent
def apply_style(s):
driver.execute_script("arguments[0].setAttribute('style', arguments[1]);",
element, s)
original_style = element.get_attribute('style')
apply_style("background: yellow; border: 2px solid red;")
time.sleep(.3)
apply_style(original_style)
Common.robot
*** Settings ***
Library SeleniumLibrary 15.0 5.0
Library OperatingSystem
Library highlight.py
Resource ../LoginPage/LoginKW.robot
*** Variables ***
${URL} https://www.involve.me/
*** Keywords ***
Start
${options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
Log To Console ${options}
Create WebDriver Chrome chrome_options=${options}
Go To ${URL}
${handles}= Get Window Handles
Maximize Browser Window
Verify Current URL
${SCREEN_TEXTS} Read Json ../../TestData/Involve_Test.json
Set Global Variable ${SCREEN_TEXTS}
Read Json
[Documentation] The function, with its' own keyword reads the json files.
[Arguments] ${file_path}
${JSONContent} Get File ${file_path}
${page}= Evaluate json.loads("""${JSONContent}""") json
[Return] ${page}
Close My Browser
Sleep 2s
Close All Browsers
Click For Element
[Arguments] ${element}
Highlight ${element}
Wait Until Element Is Visible ${element}
Click Element ${element}
Input For Text
[Arguments] ${element} ${input}
Wait Until Element Is Visible ${element}
Highlight ${element}
Input Text ${element} ${input}
LoginTC.robot
*** Settings ***
Documentation Test Case Login
Library SeleniumLibrary
Resource ../../PageObjects/LoginPage/LoginKW.robot
Resource ../../PageObjects/Common/common.robot
Test Setup Start # Suitw Setup will run only once
Test Teardown common.Close My Browser
*** Test Cases ***
Test Login
sleep 3s
Click Cookie
Click On Link Login
Enter Email [email protected]
Enter Password abcdefghijk3Only
Click On Sign in button
Is Text Displayed ${SCREEN_TEXTS["ws_page_title"]}
When i run the script getting the error.
(venv) C:\Users\User\PycharmProjects\InvolvemeRobotFramework\TestCases\Login> robot LoginTC1.robot
LoginTC1 :: Test Case Login
Test Login <selenium.webdriver.chrome.options.Options object at 0x041902B0>
DevTools listening on ws://127.0.0.1:61649/devtools/browser/4914f52f-47f6-4632-a776-02045dda890c https://www.involve.me/ ..F.....[28328:8120:0508/220557.776:ERROR:device_event_log_impl.cc(222)] [22:05:57.777] USB: usb_device_handle_win.cc:1046 Failed to read descriptor from node connec tion: A device attached to the system is not functioning. (0x1F) Test Login | FAIL | AttributeError: 'str' object has no attribute '_parent'
Can someone please help me
highlightkeyword? Because RF complains about str, I would guess you are passing XPath or similar as a string. You can debug it by logging the type and contents of theelementvariable. You can also try TRACE loglevel with-L TRACE.Click Cookiefails. Somewhere in that keyword, you might have this keyword:Highlight //div[@id='cookiescript_accept']. You cannot pass XPath to highlight function because it requires an element. You need to have something like this before:${element}= Get WebElement //div[@id='cookiescript_accept']and pass${element}to the Highlight keyword.