如何使用python和selenium将文本发送到类型属性为隐藏的输入元素

如何使用python和selenium将文本发送到类型属性为隐藏的输入元素,python,selenium,selenium-webdriver,webdriver,hidden,Python,Selenium,Selenium Webdriver,Webdriver,Hidden,我不熟悉python和selenium。我想点击get_likes_按钮,这样做时需要发送值=18033459909687013485 这是HTML <form action="" method="post" accept-charset="utf-8"><span style="font-size: 14px;"> <i class="fa fa-heart" style="color: #F12938;"></i> 20 </span

我不熟悉python和selenium。我想点击
get_likes_按钮
,这样做时需要发送值=18033459909687013485


这是HTML

<form action="" method="post" accept-charset="utf-8"><span style="font-size: 14px;"> 
<i class="fa fa-heart" style="color: #F12938;"></i> 20 </span> 
<input type="hidden" value="1803345990687013485" name="id">
<button class="btn btn-primary pull-right" type="submit" name="submit"
 id="get_likes_button"> Get Likes </button> </form></b>
我得到以下信息

异常:消息:元素不可见。


请尝试下面的代码片段。希望这对你有帮助

WebDriver driver = new FirefoxDriver();
driver.navigate().to(URL);                    
JavascriptExecutor javascriptExecuter = (JavascriptExecutor)driver;
javascriptExecuter.executeScript("document.getElementsByName('id')[0].value='452525252525';");
driver.findElement(By.id("get_likes_button")).submit();

单击“获得喜欢”按钮时,可以使用以下代码:

get_likes = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.ID, "get_likes_button")))  
之后,如果输入类型从
type='hidden'
更改,则可以通过以下方式与输入字段交互:

input_field = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.NAME, "id")))  
看到这样的HTML很奇怪:

<input name="id">  

顺便说一下,希望这会有所帮助。

此错误消息

Exception: Message: Element not visible.
…表示所需元素不可见

主要问题是
标记具有属性
type=“hidden”

要将字符序列1803345990687013485发送到输入字段并调用按钮上的
单击()

driver.execute_script("document.getElementsByName('id')[0].setAttribute('type','text')")
driver.find_element_by_xpath("//input[@name='id']").send_key('1803345990687013485')
driver.find_element_by_xpath("//button[@class='btn btn-primary pull-right' and @id='get_likes_button']").click()

你从哪里得到例外?请注意,第一个元素具有
type='hidden'
属性。另外,
get_likes_button
id
,而不是
name
。使用findElementById(),因为get_likes_button是id。我将其更改为findElementById(),但仍然收到与上面用java编写的代码相同的错误消息。使用JavascriptExecutor更新上述隐藏字段值。
driver.execute_script("document.getElementsByName('id')[0].setAttribute('type','text')")
driver.find_element_by_xpath("//input[@name='id']").send_key('1803345990687013485')
driver.find_element_by_xpath("//button[@class='btn btn-primary pull-right' and @id='get_likes_button']").click()