Python Selenium找不到要发送\u键的字段元素

2024-10-02 14:26:11 发布

您现在位置:Python中文网/ 问答频道 /正文

Overlay or Frame我正在尝试使用Python代码,以便在发货时使用特定字段中的跟踪号更新我的DISCOG

当我检查该字段框时,这是代码(也显示在我的附件中)

input type="text" class="full_width push_down_mini" style="margin-right:0;" placeholder="Tracking number (optional)" data-reactid=".0.$=1$react-modal-overlay.$react-modal.3.0.3"

我很擅长使用driver.find_element_by_ID{}和Name导航。但是无法找到使用什么来定位这个字段框元素,这样我就可以使用search.send_keys。我试过{}&class但没有运气错误返回,无法找到元素

Screenshot of Discogs field and code


Tags: or代码text元素input附件typeframe
1条回答
网友
1楼 · 发布于 2024-10-02 14:26:11

具有多个类名的input字段,即full_widthpush_down_mini。所以我认为css选择器是最好的方法

在这种情况下,您不能使用.find_element_by_class_name,因为这只是一个类名

#更新

尝试下面的代码,使用.find_element_by_css_selector

#update here
driver.switch_to.frame(driver.find_element_by_id('onetrustIabCookie'))

search = driver.find_element_by_css_selector('input.full_width.push_down_mini')
search.send_keys('your key')

或使用.find_element_by_xpath

search = driver.find_element_by_xpath('//input[@class="full_width push_down_mini" and contains(@placeholder, "Tracking number")]')
search.send_keys('your key')

相关问题 更多 >