1

After all unsuccessful tries I had to ask for the help. The thing is I want to make script which will automatically login, go to specific tab ("WAN"), click appropriate check box (to disable NAT) and log out. (It's actually Huawei GPON router HG8245)..

My code goes fine until the check box, so...

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re

driver=webdriver.Chrome(r"C:\chromedriver.exe") #load the driver => OK
driver.get("http://192.168.100.1") #go to this web page => OK
driver.find_element_by_id("txt_Username").send_keys("root") #username=root => OK
driver.find_element_by_id("txt_Password").send_keys("root") #password=root => OK
driver.find_element_by_xpath(".//*[@id='button']").click() #click Submit button => OK
driver.find_element_by_xpath(".//*[@id='headerTab']/ul/li[2]/div[2]").click() #Go to the 'WAN' tab => OK

And for the clicking of check box my tries:

#1
driver.find_element_by_xpath("//input[@value='InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1']").click()  #=> NOT OK
#2
driver.find_element_by_xpath("//*[@id='record_1']/td[1]/input").click() #=> NOT OK
#3
driver.find_element_by_css_selector("#record_1 > td > input[name=\"rml\"]").click() #=> NOT OK

Of course all xpaths are checked in chrome via console (in the Mozilla as well) and they seems fine! Any ideas how to solve this?

HTML Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
   <head>
   <body>[![enter image description here][1]][1]
      <div id="main">
      <div id="header">
      <div id="center" style="height: 495px;">
      <div id="nav" style="height: 495px;">
      <div id="content" style="height: 495px;">
      <div id="topNav">
      <div id="frameWarpContent" style="height: 470px;">
      <iframe id="frameContent" marginheight="0" marginwidth="0" scrolling="no" src="html/network/wan.asp" style="height: 470px;" height="100%" frameborder="0" width="100%">
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html id="Page" xmlns="http://www.w3.org/1999/xhtml" dir="ltl">
         <head>
         <body class="mainbody">
            <script language="JavaScript" src="../../resource/common/util.js?1103405">
            <script language="JavaScript" src="../../resource/english/jsdiff.js?1103405">
            <script language="JavaScript" src="../../resource/common/tabdes.js?1103405">
            <script language="javascript" src="../common/manage_mode.asp">
            <script language="javascript" src="../common/user_info.asp">
            <script language="javascript" src="../common/topo_info.asp">
            <script language="javascript" src="../common/feature_info.asp">
            <script language="javascript" src="../common/wan_prefix_acquire.asp">
            <script language="javascript" src="../common/wan_address_acquire.asp">
            <script language="javascript" src="../common/wan_dns.asp">
            <script language="javascript" src="../common/wan_list.asp">
            <script language="javascript" src="../common/wlan_list.asp">
            <script language="javascript" src="../common/lanmode_list.asp">
            <script language="javascript" src="../common/policyroute_list.asp">
            <script language="javascript" src="wan_language.html?1103405">
            <script language="javascript" src="../common/wan_pageparse.html?1103405">
            <script language="javascript" src="../common/wan_databind.html?1103405">
            <script language="javascript" src="../common/wan_control.html?1103405">
            <script language="javascript" src="../common/wan_check.html?1103405">
            <script language="JavaScript" src="../../resource/english/bbspdes.html?1103405">
            <script>
            <div id="PromptPanel">
            <script>
            <table width="100%" cellspacing="0" cellpadding="0" border="0">
            <tbody>
            <tr>
            <tr>
            <td id="Wan Connection">
            <table id="wanInstTable" class="tabal_bg" width="100%" cellspacing="1">
            <tbody>
            <tr class="tabal_title">
            <tr id="record_0" class="tabal_01" onclick="selectLine(this.id);">
            <tr id="record_1" class="tabal_01" onclick="selectLine(this.id);">
            <td align="center">
            <input name="rml" value="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1" onclick="" type="checkbox">
            </td>
            <td align="center">
            <td align="center">
            <td title="RealName :HSI Status :Connected IPAddress :10.10.10.10" align="center">
            </tr>
            </tbody>
            </table>
            <script>
            <form id="ConfigForm">
            </td>
            </tr>
            </tbody>
            </table>
            </body>
            </html>
            </iframe>
            </div>
            </div>
            </div>
            <div id="footer">
            <div id="fresh">
            </div>
            </body>
            </html>

*Edit: Modifying code tags and IP values

1 Answer 1

1

Considering provided HTML code sample you need to switch to iframe before handling check-box:

driver.switch_to.frame("frameContent")
driver.find_element_by_xpath("//tr[@id='record_1']//input").click()
Sign up to request clarification or add additional context in comments.

3 Comments

God Bless you!!! Can you please tell me how you concluded this so I can understand? Thank you!!!!
iframe is an HTML document rendered inside base HTML. You cannot handle elements of embedded iframe without switching to it. To check whether element located inside frame/iframe - just check ancestors. In your case there is <iframe id="frameContent" marginheight="0" marginwidth="0" scrolling="no" src="html/network/wan.asp" style="height: 470px;" height="100%" frameborder="0" width="100%"> ancestor of target input
Clear! One more time BIG tnx my dear!

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.