该公司有 100 多个网站的列表,我正在尝试使用 Selenium webdriver 自动将用户带入该网站。我对编程相当陌生,所以如果我的问题措辞不好,请原谅我。但是,我试图从用户那里获取一个网站的名称,例如下面示例中的“Alpharetta - Cemex”,并在这么长的内容中找到它列表,然后选择该链接。通过测试,我非常确定我需要单击的元素是h3 类,该类还保存data-hmi-name下的站点名称
网站代码示例:
我尝试过使用下面的方法,但它似乎从来没有工作过..
driver.find_element_by_css_selector("h3.tru-card-head-text uk-text-center[data-hmi-name='Alpharetta - Cemex']").click()
#For this one I tried to select the h3 class by searching for all those elements that has the name Alpharetta - Cemex
或者
**theCards = main.find_elements_by_tag_name("h3")** #I tried both of these declarations for theCards
**#theCards = main.find_elements_by_class_name("tru-card-wrapper")**
#then used the loop below. This obviously didn't work and it just returns an error that card.text doesn't actually exist
for card in theCards:
#title = card.find_elements_by_tag_name("h3")
print(card.text)
if(card.text == theSite):
card.click()
任何帮助或指导将不胜感激!我是 Python 编程新手,如果你能解释我做错了什么,我将永远感激不已!
慕姐8265434
相关分类