Python Forum

Full Version: How find link element
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I want click on link with text "Toner"
from selenium import webdriver


adm ='http://10.27.20.49/web/guest/br/websys/webArch/mainFrame.cgi'
# create a new Firefox session
driver = webdriver.Chrome(r'C:\Users\me\Downloads\chromedriver.exe')
driver.implicitly_wait(30)
driver.maximize_window()
driver.get(adm)
# I try another options, but still not working
I_want_click_on_link = driver.find_element_by_link_text("Toner").click()
entire element below
<a href="javascript:wsMenu_jumpUrl('../../websys/webArch/getStatus.cgi#linkToner');" class="">Toner</a>
Error
Error:
raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"link text","selector":"Toner"} (Session info: chrome=80.0.3987.149)
At first I wondered why you would have a 30 delay.
What is this site? I gave up waiting after a while.
good luck
Hi

About this line driver.implicitly_wait(30), it's a mistake, would be driver.implicitly_wait(3)
About your question, I acess my printer via browser.

I need check all level of each Toner, I have 8 printers.
If i do test local i can find the element with Toner text and click to execute the JavaScript code.
The test look like this.

local_javascript.html
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Title of the document</title>
  </head>
  <body>
   <h1>Hello world test</h1>
   <a href="javascript:alert('Hello World!');">Toner</a>
  </body>
</html>
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time

options = Options()
#options.add_argument("--headless")
#options.add_argument("window-size=398,256")
browser = webdriver.Chrome(executable_path=r'C:\cmder\bin\chromedriver.exe', options=options)
browser.get('file:///E:/div_code/scrape/sel_screenhot/local_javascript.html')
time.sleep(5)
I_want_click_on_link = browser.find_element_by_link_text("Toner").click()
How dos rest of html look when load it browser?
http://10.27.20.49/web/guest/br/websys/webArch/mainFrame.cgi
Could try to locate bye CSS selector or Xpath,right click inspect when over tag in dev tools.
The Copy --> Selector or XPath.
Usage then is.
I_want_click_on_link = driver.find_element_by_css_selector('.something')
I_want_click_on_link[0].click()