Monday, 21 December 2020

Selenium: How to find element in

I'd like to execute find_element_by_class_name using selenium in google colaboratory.

The following error was displayed.

NoSuchElementException: Message: no such element: Unable to locate element

I found this page was generated by javascript after executing print(driver.page_source).

    <body>
        <script src="../public/vendor.bundle.js"></script>
        <script src="../public/bundle.js"></script>
    </body>

The class name <div class="Graph"> is displayed when I check the chrome developer tool (F12).

How can I get this class using selenium?

edit

html is as below;

<!doctype html>
<html>
    <head>
        <title>xxx</title>

        <link rel="shortcut icon" href="../public/favicon.ico" />
        <link rel="stylesheet" type="text/css" href="../public/bundle.css">

        <script type="text/javascript">

            var contextPath = "/xxx";

            if(location.pathname.match(/(.*)(\/\S*\/\S*)/)){
                contextPath = RegExp.$1;
            }

            window.raise = window.raise || {};
            window.raise.appInfo = {
                "xxx" :  'xxx',
                "xxx" : xxx,
                .
                .
                .
            };
        </script>
    </head>
    <body>
        <div id="app-progress" class="AppInitializing"></div>
        <div id="root">

            <noscript>
                <p class="xxx">xxx</p>
            </noscript>
        </div>

        <script src="../public/vendor.bundle.js"></script>
        <script src="../public/bundle.js"></script>
    </body>
    
    
</html>

edit

"Elements" tab in Chrome developer tool is as below;

.
.
<div class="main-body-wrapper">
    <div class="main-body-area">
        <div class="page-grid single GraphPage">
            <h3 class="page-title">...</h3>
                <div class="graph-container">
                    <div class="Graph">
                        <div class="loading">...</div>
                        <div>...</div>
.
.

Python code is as below;

.
.
driver.find_element_by_id("openGraphPage").click()
time.sleep(3)
driver.get(r'https://example.com/graph')
time.sleep(10)
print(driver.current_url)
print(driver.page_source)

graph = driver.find_element_by_class_name("Graph")
.
.

Although I tried find_element_by_xpath, the result was same.



from Selenium: How to find element in

No comments:

Post a Comment