繁体   English   中英

我想使用 Selenium 和 Python 在网页中查找元素,如何获取输入值?

[英]I wanna find an element in a webpage using Selenium and Python, how can I obtain the input value?

这是我正在使用的网站部分。 具体来说,我想从 . 我可以在 Selenium 中使用best_offer = driver.find_element_by_class_name('showBestOffer')访问 span 类,有没有办法可以获取标签内的值?

<div class="ebayBestOfferAccepted" id="363858864519-bestOffer-simple"><div class="bestOfferSoldPrice" style="display: flex; align-items: center; justify-content: center;"><span class="bestOfferData"><b>Best Offer Accepted Price:&nbsp;&nbsp;</b></span><span class="bestOfferLink"><span class="showBestOffer"><input type="submit" value="15.00 USD"></span></span></div></div>
best_offer = driver.find_element_by_class_name('showBestOffer').get_text()

你可以试试这个解决方案

span = driver.find_element(By.CSS_SELECTOR,"span[class='showBestOffer']")
input = span.find_element(By.TAG_NAME, "input")
bestOffer = input.get_attribute("value")

使用 xpath

input = driver.findElement(By.xpath('//span[@class="showBestOffer"]/input'))
val = input.get_attribute("value")

暂无
暂无

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

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