简体   繁体   English

无法使用python在硒中使用CSS_SELECTOR定位元素

[英]Unable to locate the element using CSS_SELECTOR in selenium using python

I've been trying to locate and click() a javascript rendered image. 我一直试图找到并单击()一个JavaScript渲染图像。 Using css_selector I'm able to locate the element, however, I have to hover over the 1st element of the table in order to capture the location of the image. 使用css_selector我可以找到该元素,但是,我必须将鼠标悬停在表的第一个元素上才能捕获图像的位置。

<tbody>
<tr __gwt_row="0" __gwt_subrow="0" class="GPBYFDECG">
    <td class="GPBYFDEBG GPBYFDEDG GPBYFDEEG datagridCellStyle"><div style="outline-style:none;" __gwt_cell="cell-gwt-uid-6847" tabindex="0">ACD CALL DETAILS NEW</div></td>
    <td class="GPBYFDEBG GPBYFDEDG datagridCellStyle"><div style="outline-style:none;" __gwt_cell="cell-gwt-uid-6848">sup001</div></td>
    <td class="GPBYFDEBG GPBYFDEDG datagridCellStyle"><div style="outline-style:none;" __gwt_cell="cell-gwt-uid-6849">2019-01-22 01:05:57</div></td>
    <td class="GPBYFDEBG GPBYFDEDG datagridCellStyle"><div style="outline-style:none;" __gwt_cell="cell-gwt-uid-6850"><img onload="this.__gwtLastUnhandledEvent=&quot;load&quot;;" src="http://172.00.00.00.00:8889/ameyoreports/AmeyoReportsApp/clear.cache.gif" style="width:16px;height:16px;background:url(http://172.00.00.00:8889/ameyoreports/AmeyoReportsApp/0210CFCB6CBE82D7E9FAC82D9F901495.cache.png) no-repeat -308px -25px;" border="0"></div></td>
    <td class="GPBYFDEBG GPBYFDEDG datagridCellStyle"><div style="outline-style:none;" __gwt_cell="cell-gwt-uid-6851">SUCCESS</div></td><td class="GPBYFDEBG GPBYFDEDG datagridCellStyle"><div style="outline-style:none;" __gwt_cell="cell-gwt-uid-6852"></div></td>
    <td class="GPBYFDEBG GPBYFDEDG gwt-Clickable-Custom"><div style="outline-style:none;" __gwt_cell="cell-gwt-uid-6853"><img onload="this.__gwtLastUnhandledEvent=&quot;load&quot;;" src="http://172.00.00.00.00/ameyoreports/AmeyoReportsApp/clear.cache.gif" style="width:24px;height:24px;background:url(http://172.00.00.00:8889/ameyoreports/AmeyoReportsApp/0210CFCB6CBE82D7E9FAC82D9F901495.cache.png) no-repeat -406px 0px;" border="0"></div></td>
    <td class="GPBYFDEBG GPBYFDEDG gwt-Clickable-Custom"><div style="outline-style:none;" __gwt_cell="cell-gwt-uid-6854"></div></td><td class="GPBYFDEBG GPBYFDEDG"><div style="outline-style:none;" __gwt_cell="cell-gwt-uid-6855"></div></td><td class="GPBYFDEBG GPBYFDEDG GPBYFDEOG gwt-Clickable-Custom"><div style="outline-style:none;" __gwt_cell="cell-gwt-uid-6856"></div></td>
</tr>
<tr __gwt_row="1" __gwt_subrow="0" class="GPBYFDEBH">
<td class="GPBYFDEBG GPBYFDECH GPBYFDEEG datagridCellStyle"><div style="outline-style:none;" __gwt_cell="cell-gwt-uid-601">ACD CALL DETAILS NEW</div></td>
    <td class="GPBYFDEBG GPBYFDECH datagridCellStyle"><div style="outline-style:none;" __gwt_cell="cell-gwt-uid-602">Administrator</div></td>
    <td class="GPBYFDEBG GPBYFDECH datagridCellStyle"><div style="outline-style:none;" __gwt_cell="cell-gwt-uid-603">2019-01-22 18:06:58</div></td>
    <td class="GPBYFDEBG GPBYFDECH datagridCellStyle"><div style="outline-style:none;" __gwt_cell="cell-gwt-uid-604"><img onload="this.__gwtLastUnhandledEvent=&quot;load&quot;;" src="http://172.00.00.00:8889/ameyoreports/AmeyoReportsApp/clear.cache.gif" style="width:16px;height:16px;background:url(http://172.00.00.00:8889/ameyoreports/AmeyoReportsApp/0210CFCB6CBE82D7E9FAC82D9F901495.cache.png) no-repeat -308px -25px;" border="0"></div></td>
    <td class="GPBYFDEBG GPBYFDECH datagridCellStyle"><div style="outline-style:none;" __gwt_cell="cell-gwt-uid-605">SUCCESS</div></td><td class="GPBYFDEBG GPBYFDECH datagridCellStyle"><div style="outline-style:none;" __gwt_cell="cell-gwt-uid-606"></div></td>
    <td class="GPBYFDEBG GPBYFDECH gwt-Clickable-Custom"><div style="outline-style:none;" __gwt_cell="cell-gwt-uid-607"><img onload="this.__gwtLastUnhandledEvent=&quot;load&quot;;" src="http://172.00.00.00:8889/ameyoreports/AmeyoReportsApp/clear.cache.gif" style="width:24px;height:24px;background:url(http://172.00.00.00:8889/ameyoreports/AmeyoReportsApp/0210CFCB6CBE82D7E9FAC82D9F901495.cache.png) no-repeat -406px 0px;" border="0"></div></td>
    <td class="GPBYFDEBG GPBYFDECH gwt-Clickable-Custom"><div style="outline-style:none;" __gwt_cell="cell-gwt-uid-608"></div></td><td class="GPBYFDEBG GPBYFDECH"><div style="outline-style:none;" __gwt_cell="cell-gwt-uid-609"></div></td><td class="GPBYFDEBG GPBYFDECH GPBYFDEOG gwt-Clickable-Custom"><div style="outline-style:none;" __gwt_cell="cell-gwt-uid-610"></div</td>
</tr>
<tr __gwt_row="2" __gwt_subrow="0" class="GPBYFDECG">
    <td class="GPBYFDEBG GPBYFDEDG GPBYFDEEG datagridCellStyle"><div style="outline-style:none;" __gwt_cell="cell-gwt-uid-6847" tabindex="0">ACD CALL DETAILS NEW</div></td>
    <td class="GPBYFDEBG GPBYFDEDG datagridCellStyle"><div style="outline-style:none;" __gwt_cell="cell-gwt-uid-6848">sup001</div></td>
    <td class="GPBYFDEBG GPBYFDEDG datagridCellStyle"><div style="outline-style:none;" __gwt_cell="cell-gwt-uid-6849">2019-01-22 01:05:57</div></td>
    <td class="GPBYFDEBG GPBYFDEDG datagridCellStyle"><div style="outline-style:none;" __gwt_cell="cell-gwt-uid-6850"><img onload="this.__gwtLastUnhandledEvent=&quot;load&quot;;" src="http://172.16.10.23:8889/ameyoreports/AmeyoReportsApp/clear.cache.gif" style="width:16px;height:16px;background:url(http://172.00.00.00:8889/ameyoreports/AmeyoReportsApp/0210CFCB6CBE82D7E9FAC82D9F901495.cache.png) no-repeat -308px -25px;" border="0"></div></td>
    <td class="GPBYFDEBG GPBYFDEDG datagridCellStyle"><div style="outline-style:none;" __gwt_cell="cell-gwt-uid-6851">SUCCESS</div></td><td class="GPBYFDEBG GPBYFDEDG datagridCellStyle"><div style="outline-style:none;" __gwt_cell="cell-gwt-uid-6852"></div></td>
    <td class="GPBYFDEBG GPBYFDEDG gwt-Clickable-Custom"><div style="outline-style:none;" __gwt_cell="cell-gwt-uid-6853"><img onload="this.__gwtLastUnhandledEvent=&quot;load&quot;;" src="http://172.16.10.23:8889/ameyoreports/AmeyoReportsApp/clear.cache.gif" style="width:24px;height:24px;background:url(http://172.00.00.00:8889/ameyoreports/AmeyoReportsApp/0210CFCB6CBE82D7E9FAC82D9F901495.cache.png) no-repeat -406px 0px;" border="0"></div></td>
    <td class="GPBYFDEBG GPBYFDEDG gwt-Clickable-Custom"><div style="outline-style:none;" __gwt_cell="cell-gwt-uid-6854"></div></td><td class="GPBYFDEBG GPBYFDEDG"><div style="outline-style:none;" __gwt_cell="cell-gwt-uid-6855"></div></td><td class="GPBYFDEBG GPBYFDEDG GPBYFDEOG gwt-Clickable-Custom"><div style="outline-style:none;" __gwt_cell="cell-gwt-uid-6856"></div></td>
</tr>
</tbody>

Now, I need to click on the 7th child of the first row, which changes dynamically. 现在,我需要单击第一行的第7个子项,该子项会动态更改。 First, It will be a different image and after processing, it will be a PNG button which can be clicked and the reports can be downloaded. 首先,它将是一个不同的图像,经过处理后,它将是一个PNG按钮,可以单击该按钮并可以下载报告。

By using the code below I was able to find the required element. 通过使用下面的代码,我能够找到所需的元素。 However, I had to manually hover over the first row in order to do so. 但是,我必须手动将鼠标悬停在第一行上。 Additionally, If I hover over 2nd or 3rd row accidentally, content of 2nd and 3rd row will be downloaded instead of first. 另外,如果我不小心将鼠标悬停在第二行或第三行上,则会下载第二行和第三行的内容,而不是第一行。

WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".GPBYFDEKG:nth-child(7) img"))).click() 

Is there any way I can click on the 7th child of first row whithout manually hover over it? 有什么方法可以单击第一行的第7个孩子,而无需手动将鼠标悬停在它上面?

I'm not sure it will work in Python or not but you can try the below XPaths: 我不确定它是否可以在Python中运行,但是您可以尝试以下XPath:

//tr[@__gwt_row='0']/td[last()]

or 要么

(//tr[@__gwt_row='0']/td)[7]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 selenium 无法使用方法定位元素:无法通过 id、css_selector、xpath、链接文本找到元素 - selenium Unable to locate element using methods: cannot find elements by id, css_selector, xpath, link text 收到消息:没有这样的元素:无法找到元素:{&quot;method&quot;:&quot;css selector&quot;,&quot;selector&quot;:&quot;[id=&quot;None&quot;]&quot;} Python 使用 selenium 时 - Getting Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="None"]"} Python when using selenium 使用 Selenium Python 选择下拉菜单 - 无法定位元素:{“method”:“css selector”,“selector”:"[id= - Selecting drop-down using Selenium Python - Unable to locate element: {“method”:“css selector”,“selector”:"[id= Selenium/Python 无法在 CSS_SELECTOR 中使用 `:contains()` - Selenium/Python Unable to use `:contains()` in CSS_SELECTOR 如何使用css_selector选择硒python? - How to select with css_selector selenium python? NoSuchElementException:无论我使用哪个选择器(xpath、css_selector、fullXpath 等),Selenium 都无法找到搜索栏 - NoSuchElementException: Selenium unable to locate search bar regardless of which selector I use (xpath, css_selector, fullXpath etc..) 无法使用 selenium python 定位元素 - Unable to locate an element using selenium python 无法通过 xpath 使用 Selenium 和 Python 定位元素 - Unable to locate element by xpath using Selenium with Python 无法使用硒(Python)定位元素 - Unable to locate element using selenium (Python) 无法使用硒在 Python 中定位元素 - Unable to locate element in Python Using selenium
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM