I'm trying to run a script that automate a certain task. Which is:
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()
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')))