Issue
So I wanted to create a simple program that when executed, opens a chrome website, goes to my router's settings page, and modify the speed of the internet as I request from the program. This is my code in Python 3.9 and I am using the Selenium library.
import time
from selenium import *
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
usr = "admin"
psr = "Administrator"
url = "http://192.168.1.1/html/content1.asp"
url2 = "http://192.168.1.1/html/content1.asp"
s = Service("D:\chromedriver.exe")
driver = webdriver.Chrome(service=s)
driver.get(url)
driver.find_element(by=By.NAME, value="Username").send_keys(usr)
# driver.find_element_by_name("Username").send_keys(usr)
driver.find_element(by=By.NAME, value="Password").send_keys(psr)
# driver.find_element_by_name("Password").send_keys(psr)
driver.find_element(by=By.ID, value="btnLogin").click()
# driver.find_element_by_id("btnLogin").click()
driver.find_element(by=By.CSS_SELECTOR, value="#link_Admin_1").click()
It successfully logs into the router, redirects to the next site, but fails to do anything beyond this line:
driver.find_element(by=By.CSS_SELECTOR, value="#link_Admin_1").click()
It keeps giving me: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"#link_Admin_1"}
More information: The website's address is 192.168.1.1, after login, it's 192.168.1.1/html/content1.asp
I am a complete newbie to Selenium, but I am okay with python. The login part is successful. However, No matter the method I try to find the element, either by ID, CSS_SELECTOR, CLASS_NAME
Edit: More elaboration: 1- For the second page, I noticed that none of the frames that the page contained appear on the page source(https://pastebin.com/rvj84eCY). 2- So I can only see the frame and its elements using chrome's Inspect...
Solution
The page you are trying to automate contains frames. Selenium is not capable to easily traverse through the frames as each frame is the full-fledged HTML document. But Selenium has tools to switch to current frame and switch back
Answered By - Yevhen B
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.