简体   繁体   中英

I can log but Not double click an element of local web page to extract the resulting page / using selenium:python

I walked around a lot of posts and couldn't perfor any change for double clicking on a my web page element bellow :

 <div  class="tbl-content">
                <table class="hoverTable" cellpadding="0" cellspacing="0" border="0" id="alarms">
                    <tbody>  <tr ondblclick="DoubleRowClick(this, '9', '2019-06-12 15:59:49', '2019-06-12 16:00:55');" id="NotRead">
                        <td class="NotReadCell">2019-06-12</br>15:59:49 UTC </td>
                        <td class="NotReadCell"> NAME 1 </td>
                        <td>
                            <div class='slideTwo'>
                                <input type='checkbox' value="None" id="slide9" name="check" onchange="stateCheck(this, '9');">
                                <label for="slide9"></label>
                            </div>
                        </td>
                    </tr>  <tr ondblclick="DoubleRowClick(this, '10', '2019-06-13 09:32:54', '2019-06-13 09:33:36');" id="NotRead">
                        <td class="NotReadCell">2019-06-13</br>09:32:54 UTC </td>
                        <td class="NotReadCell">  NAME 2 </td>
                        <td>
                            <div class='slideTwo'>
                                <input type='checkbox' value="None" id="slide10" name="check" onchange="stateCheck(this, '10');">
                                <label for="slide10"></label>
                            </div>
                        </td>
                    </tr>  <tr ondblclick="DoubleRowClick(this, '11', '2019-06-13 09:34:47', '2019-06-13 09:35:10');" id="NotRead">
                        <td class="NotReadCell">2019-06-13</br>09:34:47 UTC </td>
                        <td class="NotReadCell">  NAME 3 </td>
                        <td>
                            <div class='slideTwo'>
                                <input type='checkbox' value="None" id="slide11" name="check" onchange="stateCheck(this, '11');">
                                <label for="slide11"></label>
                            </div>
                        </td>
                    </tr>  <tr ondblclick="DoubleRowClick(this, '12', '2019-06-13 09:36:38', '2019-06-13 09:37:44');" id="NotRead">
                        <td class="NotReadCell">2019-06-13</br>09:36:38 UTC </td>
                        <td class="NotReadCell">  NAME 4 </td>
                        <td>
                            <div class='slideTwo'>
                                <input type='checkbox' value="None" id="slide12" name="check" onchange="stateCheck(this, '12');">
                                <label for="slide12"></label>
                            </div>
                        </td>
                    </tr>  <tr ondblclick="DoubleRowClick(this, '13', '2019-06-13 12:22:35', '2019-06-13 12:23:41');" id="NotRead">
                        <td class="NotReadCell">2019-06-13</br>12:22:35 UTC </td>
                        <td class="NotReadCell">  NAME 5 </td>
                        <td>

And my code is :

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
driver = webdriver.Chrome()
driver.get("http://1.2.3.4:82805/")
assert "Home" in driver.title
elem = driver.find_element_by_name("pwd")

#print (elem)
elem.clear()
elem.send_keys("0000")
elem.send_keys(Keys.ENTER)

driver.get("http://1.2.3.4:82805/menu.php")
driver.maximize_window()
element = driver.find_elements_by_xpath("//*[@id='NotRead']")
actions = ActionChains(driver)
actions.double_click(element).perform()

And my errors are :

Traceback (most recent call last):
  File "C:\projects_Drivers\webBrowser.py", line 19, in <module>
    actions.double_click(element).perform()
  File "C:\Users\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\common\action_chains.py", line 83, in perform
    action()
  File "C:\Users\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\common\action_chains.py", line 277, in <lambda>
    Command.MOVE_TO, {'element': to_element.id}))
AttributeError: 'list' object has no attribute 'id'

I tried a lot of solutions but i need to know if the probleme is in my python coding way or it is not possible to do what i need to do with this HTML web interface.

And my question is is that possible to click it if there is no id? Or how can I find my button to click. I can understand that the web interface is not well coded but I am not allowed to change its code or add elements. Thank you in advance

First of all find_elements_by_xpath will return list of elements, and in your code you are passing list rather element.

So,Change the below line

element = driver.find_elements_by_xpath("//*[@id='NotRead']")

to

element = driver.find_element_by_xpath("//*[@id='NotRead']")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM