簡體   English   中英

Python Selenium - 有什么方法可以在這個文本框中發送文本?

[英]Python Selenium - Any way to get send text within this textbox?

我正在嘗試 select 一個文本框來輸入一些數據,問題是我不知道如何獲取它的元素:

這就是我檢查它時得到的結果:

<input class=" input" maxlength="255" type="text" aria-describedby="" placeholder="" id="8624:0" data-aura-rendered-by="8628:0" data-interactive-lib-uid="28">

問題是,這基本上是為了填充forms,而id,render by,uid 號都變了。 有什么我可以嘗試的嗎?

要將字符序列發送到<input>元素,您需要為element_to_be_clickable()引入WebDriverWait ,並且可以使用以下任一定位器策略

  • 使用CSS_SELECTOR

     WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.input[type='text'][data-aura-rendered-by][aria-describedby]"))).send_keys("Smece")
  • 使用XPATH

     WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class=' input' and @type='text'][@data-aura-rendered-by and @aria-describedby]"))).send_keys("Smece")
  • 注意:您必須添加以下導入:

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

有沒有辦法在<div>在 python 中使用 selenium?</div><div id="text_translate"><p> 我是 python 和網絡抓取的新手,所以我不確定元素中&lt;div&gt;之間的值的名稱是什么。 很抱歉無法指定。</p><pre> &lt;div class="syllable"&gt;value&lt;/div&gt;</pre><p> 有沒有辦法使用 selenium 使用 XPath 將&lt;div&gt;之間的值分配給 python 中的字符串變量? 例如,元素中的“值”是一個字符串,它會打印出:</p><pre> value</pre><p> 我是 python 和 selenium 的新手,所以我無法弄清楚。</p></div>

[英]Is there a way to get the value within a <div> using selenium in python?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM