[英]How to send text to an input element with type attribute as hidden using python and selenium
I'm new to python and selenium. 我是python和selenium的新手。 I want to click on the
get_likes_button
and I need to send the value = 1803345990687013485 when doing that. 我想单击
get_likes_button
并且在执行此操作时需要发送值= 1803345990687013485。
Here's the HTML 这是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>
Here's the code 这是代码
driver.find_element_by_xpath("//input[@name='id']").send_key('1803345990687013485')
driver.find_element_by_id('get_likes_button').submit()
I get the following message 我收到以下消息
Exception: Message: Element not visible.
异常:消息:元素不可见。
Try below snippet. 请尝试以下代码段。 Hope this will help you.
希望这会帮助你。
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();
For clicking on Get Likes button you can use this code : 对于单击“喜欢”按钮,您可以使用以下代码:
get_likes = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.ID, "get_likes_button")))
After that if input type changed from type='hidden'
, you can interact with input field as : 之后,如果输入类型从
type='hidden'
更改,则可以与输入字段进行交互,如下所示:
input_field = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.NAME, "id")))
It's quite strange to see HTML like this : 看到这样的HTML很奇怪:
<input name="id">
By the way, hope this will help. 顺便说一句,希望这会有所帮助。
This error message... 此错误消息...
Exception: Message: Element not visible.
...implies that the desired element is not visible . ...表示所需的元素不可见 。
The main issue is the <input>
tag is having an attribute type="hidden"
. 主要问题是
<input>
标记具有属性type="hidden"
。
To send the character sequence 1803345990687013485 to the input field and invoke click()
on the button you can use the following solution: 要将字符序列 1803345990687013485发送到输入字段并在按钮上调用
click()
,可以使用以下解决方案:
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.