简体   繁体   English

slelnium python:单击没有 id 或名称的动态对象/元素

[英]slelnium python : clicking a dynamic object/element which has no id or name

when Right click is performed then an options popup/screen appears and its a dynamic content/element.当执行右键单击时,会出现一个选项弹出/屏幕,它是一个动态内容/元素。

This is the Options Popup:这是选项弹出窗口:

在此处输入图像描述

This dynamic content/element disappears as soon as the mouse is clicked somewhere else on the screen even if its clicked on the inspect element window the dynamic content/element disappears一旦鼠标单击屏幕上的其他位置,此动态内容/元素就会消失,即使它单击了检查元素 window 动态内容/元素也会消失

there are few option to select from on the popup but in the html code there is not name or id to these options, so how can i access/select them from selenium using python? there are few option to select from on the popup but in the html code there is not name or id to these options, so how can i access/select them from selenium using python?

This is How the HTML looks:这是 HTML 的外观:

在此处输入图像描述

i intend to select the option HMH NC by sending the Righ click using selenium and then making select the option but since there is no name or id for the options i can figure out how to do it我打算 select 选项 HMH NC 通过使用 selenium 发送右击然后将 select 设置为选项,但由于没有名称或选项我可以弄清楚如何

You'll have to search for it by text.您必须通过文本搜索它。 I would do something like this (untested code):我会做这样的事情(未经测试的代码):

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By    

item_labels = WebDriverWait(my_driver,5).until(
    EC.visibility_of_element_located((By.CSS_SELECTOR, "div.item span.label")),
    message="failed to find any menu items")

target = None
for item in item_labels:
    if item.get_attribute("text") == target_value:
        target = item
        break
target.click()

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

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