0
<h1 class="modalHeader"> Device Properties of test1234 </h1>

<div class="mainPopContent">
    <ul id="parent" class="tree">
        <li id="child">
            List Index: <span>1</span>
        </li>
        <li id="child">
            Device Type: <span>test 6000</span>

            <li id="child" class="has-children"><i class="js-toggle-icon">+</i>
            Network Mode
            <ul id="parent" style="display: none;">
                <li id="child">
                     Auto
                </li>
                <li id="child">
                    Firmware: <span>1.2.2.43</span>
                </li>
            </ul>
        </li>
    </ul>
 </div>

Summary : When I am clicking on "edit" button pop up modal is opening and from that modal i need to get the following details.

I need to get the Device Type and Firmware text from the modal using python selenium.

How can i achieve this issue?

Please help me

Stackrace :

DevTools listening on ws://127.0.0.1:12345/devtools/browser/af75ff22-1e5f-4493-8f56-158910238bf5
Device Type: EM 6000
Traceback (most recent call last):
  File "asif.py", line 12, in <module>
    driver.find_element_by_xpath("//div[@class='mainPopContent']/ul[@class='tree' and @id='parent']//following-sibling::li[2]/li/i[@class='js-toggle-icon']").click()
  File "C:\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 385, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)
  File "C:\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 955, in find_element
    'value': value})['value']
  File "C:\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
    self.error_handler.check_response(response)
  File "C:\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//div[@class='mainPopContent']/ul[@class='tree' and @id='parent']//following-sibling::
li[2]/li/i[@class='js-toggle-icon']"}
  (Session info: chrome=63.0.3239.132)
  (Driver info: chromedriver=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT 10.0.16299 x86_64)
3
  • What is the exact problem? What have you tried and why did it not work? From your post, I can't see if it is even necessary to use Selenium. Could you share the URL so we can see the page in question ourselves? Commented Feb 23, 2018 at 7:47
  • Do you want to extract Device Type and Firmware as text or the values i.e. test 6000 and 1.2.2.43 Commented Feb 23, 2018 at 7:58
  • Share your current code and describe the problem Commented Feb 23, 2018 at 8:20

2 Answers 2

1

I like @DebanjanB 's Waits, but that method is WAY more complex than required. This should get you there (try for surgical XPaths, they are less brittle).

find_element(By.XPATH, "//i[@class='js-toggle-icon']/..").click()
device_type = find_element(By.XPATH, "//li[contains(text(), 'Device Type')]/span").text
firmware = find_element(By.XPATH, "//li[contains(text(), 'Firmware')]/span").text
Sign up to request clarification or add additional context in comments.

2 Comments

Works fine if you add time.sleep(5) above your 3 lines of code.
@Tola time.sleep is a great way to write slow, expensive test suites. Use Explicit Waits, save yourself and your team time and money.
0

As per the HTML to extract the text Device Type from the modal you can use the following line of code :

Device_Type_element = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "//div[@class='mainPopContent']/ul[@class='tree' and @id='parent']//following-sibling::li[2]")))
Device_Type = Device_Type_element.text

To click on Network Mode you can use the following line of code :

Network_Mode = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='mainPopContent']/ul[@class='tree' and @id='parent']//following-sibling::li[2]//i[@class='js-toggle-icon']")))
Network_Mode.click()

Finally, as per the HTML to extract the text Firmware from the modal you have to remove the style="display: none;" first and you can use the following line of code :

Firmware_webelement = driver.find_element_by_xpath("//div[@class='mainPopContent']/ul[@class='tree' and @id='parent']//following-sibling::li[2]//ul//following::li[2]")
driver.execute_script("arguments[0].removeAttribute('style')", Firmware_webelement)
Firmware = driver.find_element_by_xpath("//div[@class='mainPopContent']/ul[@class='tree' and @id='parent']//following-sibling::li[2]//ul//following::li[2]").text

8 Comments

Firmware is not working...To get text from firm ware i need to click on "Network mode". Here is the html code : I need to click on the Network mode...<li id="child" class="has-children"><i class="js-toggle-icon minus">-</i> Network Mode <ul id="parent" style=""> <li id="child"> Auto </li> <li id="child"> Firmware: <span>1.2.2.43</span> </li> </ul> </li>
How can i click? Please help me
Thanks but i want to click on "network mode"..That's my requirement in test case...How to click on "Network mode" Please help me
It's not working...I need to click on network mode then the text will be visible.It's inside Network mode
I'm getting this error : Message: no such element: Unable to locate element: {"method":"xpath","selector":"/
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.