Requiring line of code to select nature of payment from drop down list

时间秒杀一切 提交于 2020-01-22 02:49:26

问题


I complied the below mentiond code line, but it is not working. I'm not able to figure out how to select nature of payment , the nature of payment tab is marked between arrows in the attached image.

Sub TDS_Autofill()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.navigate "https://onlineservices.tin.egov-nsdl.com/etaxnew/tdsnontds.jsp"
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop

Set doc = IE.document

doc.parentWindow.execScript "sendRequest(281)", "JavaScript"

Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop


If ThisWorkbook.Sheets("Challan AutoFill").Range("m2").Value = "Company" 
Then
doc.getElementById("0020").Click
ElseIf ThisWorkbook.Sheets("Challan AutoFill").Range("m2").Value = "Non 
Company" Then
doc.getElementById("0021").Click
End If



If ThisWorkbook.Sheets("Challan AutoFill").Range("o2").Value = "(200) 
TDS/TCS Payable by Taxpayer" Then
doc.getElementById("200").Click
ElseIf ThisWorkbook.Sheets("Challan AutoFill").Range("o2").Value = "(400) 
TDS/TCS Regular Assessment" Then
doc.getElementById("400").Click
End If

doc.getElementsByName("NaturePayment").Value = ThisWorkbook.Sheets("Challan 
AutoFill").Range("q2").Value



End Sub

回答1:


You can use selectedIndex on the select itself then specify index of option of interest in the list under that select. I

ie.document.querySelector("select.form-control").SelectedIndex = 2 '3 or 3 etc....

Or

Use .Selected = True on the option element itself e.g.

ie.document.querySelector("[value='193 - Interest on Securities']").Selected = True



回答2:


the getElementsByName method returns an array of elements, even if there is only one element with that name. You have to use getElementsByName("NaturePayment")(0).Value instead.



来源:https://stackoverflow.com/questions/58302998/requiring-line-of-code-to-select-nature-of-payment-from-drop-down-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!