0

I'm trying to run a script that automate a certain task. Which is:

  1. Chrome searches website
  2. Login to website (Fill in details)
  3. Navigate to a tab (Called Jobs Listings V2)
  4. Input a product barcode on "Jobs Listing V2"
  5. Capture XML data that search returns and save to an XLS file
  6. Repeat for the next barcode

I'm currently stuck on step 3 where no matter what my code is it stays on the homepage of the website.

My current code so far is

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from webdriver_manager.chrome import ChromeDriverManager

options = Options()
options.add_experimental_option("detach", True)

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)

driver.maximize_window()

driver.get("https://brands.silo.co.za/#/Job/JobListingV2")

full_name_input = driver.find_element(By.ID, "Fullname")
full_name_input.send_keys("Meeaad Bharoochi")

full_name_input = driver.find_element(By.ID, "Password")
full_name_input.send_keys("Password@1")

submit_button = driver.find_element(By.CLASS_NAME, "btn-primary")
submit_button.click()

anchor_element = driver.find_element(By.LINK_TEXT, "Job Listing V2")
anchor_element.click()
<body>
    <div class="wrapper">
        
<nav class="navbar navbar-inverse navbar-fixed-top" style="height:auto !important; border:0;">
    <div class="container-fluid" style="margin: 0 !important">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#siloMenuItems" aria-expanded="false">
                <span class="sr-only"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#/Job/GetQAL">
                <img src="/Images/Silo_logo.png" style="width: auto; height: auto;" alt="">
            </a>
        </div>
        <div class="collapse navbar-collapse" id="siloMenuItems">
            <ul class="nav navbar-nav">
                                    <li class='active dropdown'>
                        <a href="#/SourceRequest/Index" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                            Dashboard <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu">
                            <li>
                                <a href="#/SourceRequest/Index">Sourcing</a>
                            </li>
                            <li>
                                <a href="#/SalesRep/Dashboard">Sales Reps</a>
                            </li>
                            <li>
                                <a href="#/SalesRep/RequestsRequiringAttention">Product Line listings requiring attention</a>
                            </li>
                        </ul>
                    </li>
                                                                
                                    <li class="dropdown">
                        <a href="javascript:return;" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                            Sourcing <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu multi-level" role="menu" aria-labelledby="dropdownMenu">
                            <li class="dropdown-submenu">
                                <a tabindex="-1" href="javascript:return;">Sourcing Statuses</a>
                                <ul id="_sourcingContext" class="dropdown-menu"></ul>
                            </li>
                            <li class="dropdown-submenu">
                                <a tabindex="-1" href="javascript:return;">Feeds</a>
                                <ul class="dropdown-menu">
                                    <li>
                                        <a href="/#/Import/Index">Import Media Tracker Sourcing Requests</a>
                                    </li>
                                    <li>
                                        <a href="/#/ImportProductMaster/Index">Import Retailer Module Sourcing Requests</a>
                                    </li>
                                    <li>
                                        <a href="/#/Email/Logs">Email Logs</a>
                                    </li>
                                </ul>
                            </li>
                            <li class="dropdown-submenu">
                                <a tabindex="-1" href="javascript:return;">Reports</a>
                                <ul class="dropdown-menu">
                                    <li>
                                        <a href="/#/Report/ImageStatusReport">Image Status Report</a>
                                    </li>
                                </ul>
                            </li>
                                <li>
                                    <a href="/#/SourceRequest/Create">Add sourcing request</a>
                                </li>
                            <li>
                                <a href="/#/SourceRequest/Index">Sourcing request listing</a>
                            </li>
                            <li>
                                <a href="/#/ProductRequest/Products">Product request Listing</a>
                            </li>
                            <li>
                                <a href="/#/SourceRequest/Companies">Company Overview</a>
                            </li>
                            <li>
                                <a href="/#/Ticket/Index">My Tickets</a>
                            </li>
                                                            <li class="dropdown-submenu">
                                    <a href="javascript:return;" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                                        Unique
                                    </a>
                                    <ul class="dropdown-menu">
                                        <li>
                                            <a href="#/Unique/Entry">Entries</a>
                                        </li>
                                        <li>
                                            <a href="#/Unique/Brand">Operational Off Pack Brands</a>
                                        </li>
                                    </ul>
                                </li>
                        </ul>
                    </li>
                                                    <li class="dropdown">
                        <a href="javascript:return;" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                            Jobs <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu">
                            
                            <li>
**                                <a href="/#/Job/JobListingV2">Job Listing V2</a>
**

This is html.index of the website i need to automate. Highlighted is the webpage im not able to select.

I've tried Xpaths but I am uncertain what exactly is going wrong is it the wait second?

jobs_dropdown = driver.find_element(By.XPATH, "//a[contains(@class, 'dropdown-toggle') and contains(text(), 'Jobs')]")

As well as ive tried

anchor_element = driver.find_element(By.LINK_TEXT, "Job Listing V2")
anchor_element.click()
2
  • what you've tried should work... but maybe better to target href... something like XPATH of "//a[contains(@href, "JobListingV2")]" I have a feeling the lack of webdriverwaits might be the issue here... and it sounds like you'll also need to click something first for the link to appear? The "Jobs" link with the caret? You should also avoid finding elements via class name as those are not guaranteed to be unique. Ex: submit_button = driver.find_element(By.CLASS_NAME, "btn-primary") Commented Aug 22, 2023 at 18:45
  • 1
    Hi @pcalkins Yes you are 100% correct. In terms of the "Jobs" caret it only appears once you click on the navbar header. Ive added WebDriverwaits up to 80 s. But it still props an error. I believe the Jobs link is the issue as you said. Im trying to figure it all out as this is kinda my first Python usage as well. Thumbs up i get it right! Commented Aug 24, 2023 at 18:24

1 Answer 1

0

Once again thank you to @pcalkins i have added the webdriverwait and it has done wonders for my script.

The adjustments made were

dropdown_toggle = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CLASS_NAME, 'dropdown-toggle')))
Sign up to request clarification or add additional context in comments.

Comments

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.